|
From: Joe E. <jen...@fl...> - 2008-11-20 18:39:30
|
Neil Madden wrote:
> The try/handle (Twylite/JE) alternative would be:
>
> proc async-foreach {varName list body} {
> if {[llength $list] == 0} { return }
> set list [lassign $list item]
> try {
> apply [list $varName $body] $item
> } handle {code msg opts} {
> switch $code {
> 3 { return }
> 0 - 4 { # ok/continue }
> default { return -options $opts $msg }
> }
> }
> after 0 [list async-foreach $varName $list $body]
> }
A clarification: this is not what I proposed in [1].
In a clause like:
handle {code ?resultVar ?optionsVar??} { script }
"code" would be an integer or a literal "ok"/"error"/etc.,
not a variable name. Same as the
catch code {?resultVar ?optionsVar??} { script }
form you proposed, just spelled slightly differently.
What I had in mind would look like:
try {
apply [list $varName $body] $item
} handle return {
return
} handle ok {
# no-op
} handle continue {
# no-op
}
The clause "default { return -options $opts $msg }" from
the first script is unneeded, since that's the default
behaviour of [try] when no "handle" or "onerror" clause
matches.
--Joe English
[1] <URL: http://sourceforge.net/mailarchive/message.php?msg_name=E1L2s55-0001xW-6L%40eurydice.office.flightlab.com >
|