Re: Why doesn't foreach return a value
- From: "tom.rmadilo" <tom.rmadilo@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 08:06:30 -0800 (PST)
The post title is misleading. In the typical Tcl:
% set a [foreach b {e f g} {}]
% puts $a
%
You see that a has a value, so the code [...] does return a value. But
the larger question is not why it returns or doesn't return a value,
but 'when' should it return it, and what value should it return?
Foreach actually never 'goes away', so how could it return? So it
really boils down to how it is called. Is it called as a function, or
is is simply used in the current flow of code? If it is called as a
function, it does return 'a value'. But, regardless of this, there is
simply no other value it should 'return'. If there is, then you need
to first identify what that value should be. I doubt you will find any
logical support for anything in particular.
The most obviously useful information would be some kind of metadata
which documents what happened, mostly for the case of continuing, and
maybe what state the loop was in upon exit. However, these metadata re
not really part of a normal program (if they were, you could just add
variables to record the information). They may aid debugging.
There is an instrumented for/foreach/while in the new AOLserver code:
http://aolserver.cvs.sourceforge.net/aolserver/aolserver/nsd/tclloop.c?view=markup
This allows you to find all running loops and perform: "list", "info",
"pause", "resume", "cancel", "eval", "install". I assume this code was
added to track down misbehaving loops and figure out why they are not
working without needing to restart an entire process (plus you can't
easily debug a loop error without live data).
.
- Follow-Ups:
- Re: Why doesn't foreach return a value
- From: Darren New
- Re: Why doesn't foreach return a value
- References:
- Re: Why doesn't foreach return a value
- From: Rufus V. Smith
- Re: Why doesn't foreach return a value
- From: Mark Janssen
- Re: Why doesn't foreach return a value
- Prev by Date: Re: Package unloading
- Next by Date: Re: Package unloading
- Previous by thread: Re: Why doesn't foreach return a value
- Next by thread: Re: Why doesn't foreach return a value
- Index(es):
Relevant Pages
|