我想将Tcl键列表传递给一个函数,当我访问函数中的变量时,其类型不是键列表。用于获取密钥列表的软件包是TclX。将TCL键列表作为参数传递给函数会改变其类型
示例代码:
keylset x port1.port "1/1"
keylset x port1.stream "1"
# keylkeys x works at this point
keylset y port1.port "1/1"
keylset y port2.port "1/2"
keylset y port1.stream "1"
# keylkeys y works at this point
# Following call returns error: the error is keyed list entry must be a valid, 2 element list, got "port1"
proc_name $x
# Following call is successful
proc_name $y
# procedure is part of a package and the package is sourced at the start of the script
proc proc_name {x} {
# puts x for one port input -> port1 {{port 1/1} {stream 1}}
# puts y for one port input -> { {port1 {{port 1/1} {stream 1}}} {port2 {port 1/1}} }
puts [keylkeys x]
}
我不知道为什么密钥列表无法识别传递到过程
'keylset'不是Tcl的标准部分。你应该包括什么扩展名提供该命令作为你的问题的一部分。假设它们不仅仅是代码中定义的过程。 – patthoyts
我正在使用TclX,编辑了包含信息的问题。 – Aditya