一个新的字典,我想编写一个PROC它可以接受字典作为optional argument或者如果没有被赋予新创建的。我的尝试,但是,失败如何设置默认值的参数proc是Tcl的
的说法符太多的领域 “词典[字典创建]”
proc getOpts { {dictionary [dict create]} } {
upvar $dictionary dct
for { set i 0 } { $i < $::argc } { incr i } {
set key [lindex $::argv $i]
if { [string index $key 0] == "-" } {
incr i
dict set dct [string trimleft $key "-"] [lindex $::argv $i]
} else {
dict set dct $key ""
}
}
}
由于dictionaries are pure values,我想这可能是工作。看起来我可能错了。不过,我想知道为什么它不起作用。
只需使用{}。但你的upvar不会工作。 –