Tcl Script: Invalid command name return when executing proc body -
in tcl script, want catch return of tcl proc in order execute finalization actions. example code follows:
proc x10 { } { return [expr $a * 10] } proc procf {} { set 13 catch {[info body x10]} __result return $__result } procf
the previous code gives me error: invalid command name " return [expr $a * 10] "
although replacing info body x10
return [expr $a * 10]
works expected. thought both of them exchangeable , should give same output. so, why first gives error , difference between both of them ?
your code failing because getting body of x10
, treating command name. tcl doesn't split things automatically — have ask — , critical language safety factor. you'd have this:
proc procf {} { set 13 catch {eval [info body x10]} __result return __result }
or (because first argument catch
script):
proc procf {} { set 13 catch [info body x10] __result return __result }
but i'd inclined in case (as presented exactly, , trying interpret you've said) do:
proc procf {} { set 13 catch {x10 $a} __result return __result }
note if did this:
proc procf {} { set 13 catch {info body x10} __result return __result }
then result definition of x10
without being evaluated.
Comments
Post a Comment