Why doesn't foreach return a value
- From: Mark Janssen <mpc.janssen@xxxxxxxxx>
- Date: Sat, 17 Nov 2007 11:52:37 -0800 (PST)
Is there any specific reason a call to foreach always returns {}? It
would be useful if it returns the last result. I could have used this
on occasion. For instance a bit of a crafted example:
proc test {l} {
foreach a $l {append b $a}
return $b
}
fails in the case $l eq {}. It needs to be:
proc test {l} {
set b {}
foreach a $l {append b $a}
return $b
}
with foreach returning a value (or {} if the body doesn't execute)
this would be:
proc test {l} {
foreach a $l {append _ $l}
}
Mark
.
- Follow-Ups:
- Re: Why doesn't foreach return a value
- From: Fredderic
- Re: Why doesn't foreach return a value
- From: Mark Janssen
- Re: Why doesn't foreach return a value
- Prev by Date: Re: TIP#308: Choice of dict as the row representation
- Next by Date: TIP #308: Twylite's concerns
- Previous by thread: global a b != global a; global b in this circumstance
- Next by thread: Re: Why doesn't foreach return a value
- Index(es):
Relevant Pages
|