Re: Why doesn't foreach return a value



On Thu, 31 Jan 2008 08:01:33 -0800 (PST),
"tom.rmadilo" <tom.rmadilo@xxxxxxxxx> wrote:

Starting at line 1811 of generic/tclCmdAH.c:
[snip]
This executes the body code of foreach (in the parent frame) and
either breaks or continues, after resetting the result code to TCL_OK.
Once out of this loop (not shown), the next code nullifies the Tcl
result.

But I think I made a mistake about one thing in a previous post. The
loop code/frame/level doesn't cross the boundary of a proc. If you use
a bare [break] or [continue], you get an error. But, if you use
[return -code break/continue],
you can get out of the current level and then out of the loop.

My, I think there might be hope yet. ;)

You should be able to see that it does indeed receive a value
returned. Now, if you trace that back to figure out where those
TCL_BREAK and TCL_CONTINUE values came from, you'll figure it all out.

The mistake you've made all through this thread, is that the proc isn't
the only boundary to be aware of. Individual commands have their own
boundaries, none of which are violated. Short of a setjump/longjump,
there's really very few other options, and most of them are variants of
the same theme, and very obviously non-regular returns.

[return], [continue], or [break], all send a signal back indicating
special action needs to be taken. Each level in turn, then either
handles that signal or passes it back. This signal, which includes an
"all okay, go get the result" variant, is "returned".


Fredderic
.



Relevant Pages

  • Re: Math libarary
    ... thought would have been a bette routine than Math.Exp and I was wrong;/ ... Both of these depend on S only but have to take into account the boundaries. ... Right now I have two functions that essentially loop over S seperately. ... The following is the code I use to compute the laplacian of a scalar field. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How can I speed up this for loop?
    ... Ian Cowley wrote: ... >>> You're not actually changing anything inside the loop, ... As far as types of boundaries go, I'm trying to model 3 different ... matrices which correspond to the boundary node of u to zero. ...
    (comp.soft-sys.matlab)
  • Re: more CommEvents than expected
    ... He resets proc to 0 at the beginning of the loop and only sets it to 1 when ... times even if WaitCommEvent is not called in the for loop. ... 1> clear dwEvtMask every time when you get into the new loop, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Stupid Question-- Why not Open-loop?
    ... > If closed- or open loop doesn't apply to a hammer, ... If not scooter, to a bicycle? ... The first thing to realise about a system is where the boundaries are going ...
    (sci.engr.control)
  • Re: Deleting in a cursor loop
    ... cursor for loop and an iterative commit within the loop every 300,000 ... This is the proc: ... CURSOR delrowcur IS ... IF (RCOUNT>= 300000) THEN ...
    (comp.databases.oracle.server)