Sujet : Re: where is the TCL "macro" command ?
De : aotto1968 (at) *nospam* t-online.de (aotto1968)
Groupes : comp.lang.tclDate : 28. Jun 2024, 08:05:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5lnav$37llc$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
well the "args" in "prog" should be improved ...
proc block {args} {
set code [lindex $args end]
set args [lrange $args 0 end-1]
...
}
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"
On 28.06.24 08:37, aotto1968 wrote:
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