| Mark Janssen 2008-01-30, 7:46 pm |
| On Jan 30, 7:01 pm, "tom.rmadilo" <tom.rmad...@gmail.com> wrote:
> On Jan 30, 6:02 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
>
>
>
>
>
>
> Of course the problem is what? You want [foreach] to return a value?
> No, wait, you want [break] and [continue] to set the return value of a
> [foreach] loop? What happens if [foreach] finishes without a [break]
> or [continue]?
>
> While we are at it, why not have [break] or [continue] return a value?
> That is what the above code does. And of course it doesn't work
> either:
>
> % foreach b {e f g} {break $b}
> invoked "break" outside of a loop
>
> Maybe just admit that although there are shared syntactic features,
> not all Tcl commands are the same. foreach/for/while are commands in
> Tcl, but they are just language features in most programming
> languages. This is purely syntax, they are logically the same in every
> programming language.
>
> This wish for [foreach] to return a value is really just a wish for a
> logically distinct looping feature which no programming language, not
> just Tcl, seems to support ... or maybe provide a reference, so the
> usefulness claim has some foundation.
The fact that a foreach loop evaluates its body in the current context
doesn't mean it cannot return anything. A foreach call does create a
new callframe for instance (which can be seen by making an error in
the body and examining errorInfo) So it is definitly there.
Mark
|