Hi, the following code is ugly:
proc block {args} {
set code [lindex $args end]
set args [lrange $args 0 end-1]
foreach {var val} $args {
uplevel [list push $var $val]
}
uplevel $code
foreach {var val} $args {
uplevel [list pop $var]
}
}
I want to have
macro block {args} {
local code var val
set code [lindex $args end]
set args [lrange $args 0 end-1]
foreach {var val} $args {
push $var $val
}
eval $code
foreach {var val} $args {
pop $var
}
}
the "macro" command evaluate the code IN the Frame of the calling "proc" arguments and "local" declared variables are local, all other variables
are always in the frame of the calling "proc"
mfg
the "macro" command evaluate the code IN the Frame of the calling "proc" arguments and "local" declared variables are local, all other variables
are always in the frame of the calling "proc"
* aotto1968 <aotto1968@t-online.de>
| should be
| proc block {args code} {
| ...
| }
| "args" always collect as much as possible arguments
| { args code } first set the defined "code" from the "end" and
| all remaining arguments got to "args"
Note that the TCL 'args' works differently: it is only 'magic' if it is
the *last* entry in the argument list.
Am 28.06.24 um 09:23 schrieb Ralf Fassel:
* aotto1968 <aotto1968@t-online.de>
| should be
| proc block {args code} {
| ...
| }
| "args" always collect as much as possible arguments
| { args code } first set the defined "code" from the "end" and
| all remaining arguments got to "args"
Note that the TCL 'args' works differently: it is only 'magic' if it is
the *last* entry in the argument list.
Yes, but it would indeed be useful; hence TIP 288 https://core.tcl-lang.org/tips/doc/trunk/tip/288.md
(unfortunately, rejected for 9.0)
Christian
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 970 |
Nodes: | 10 (2 / 8) |
Uptime: | 104:22:38 |
Calls: | 12,740 |
Calls today: | 2 |
Files: | 186,574 |
Messages: | 3,171,652 |