| Gerald W. Lester 2008-01-30, 7:46 pm |
| Fredderic wrote:
> On Sat, 17 Nov 2007 11:52:37 -0800 (PST),
> Mark Janssen <mpc.janssen@gmail.com> wrote:
>
>
> It is an interesting point, though... More of the control structures
> could easily return a value. I'm not entirely certain how often it'd
> actually be useful, but it might be interesting. Of more use, I think,
> would be if [break] and [continue] could return an argument. Have them
> stash it away in the options dict so you can distinguish between an
> empty value and no value at all.
You can effectively have a "break" or "continue" return a value, but doing:
proc break {{value {}}} {
return -code break -level 2 $value
}
proc continue {{value {}}} {
return -code continue -level 2 $value
}
The catch command returns the status code and takes an optional argument to
take the return value. As in:
set status [catch {break foo} bar]
puts stdout "Status = {$status}, return value = {$bar}"
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
|