我{*}
在 tcl 中用于参数扩展并遇到了这个问题。
#!/usr/bin/tclsh
set reset {
set count 0;
set age 24;
}
puts $reset
eval $reset; # This is working fine. Commented out the below line and tried
{*}$reset; # This is throwing error. Commented out the above line and tried.
if { [ info exists count ] && [ info exists age ] } {
puts "count & age initialzed to $count and $age"
} else {
puts "count & age not initialzed :("
}
如您所见,我定义了 reset 变量,并且正在评估 witheval
和 with {*}
。
虽然eval
工作正常,但{*}
抛出错误为
wrong # args: should be "set varName ?newValue?"
while executing
"{*}$reset"
然后我将变量更改reset
如下,
set reset {
set count 0;
}
即我已经删除了第二条set
语句并且代码工作正常。
为什么{*}
使用一个语句可以正常工作,而不是更多?或者我在这里缺少什么?