我想將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