我试图写一个小效用函数,将确定以下形式的表结构的存在:TCL:字符串是整数或列表或字符串或不之间的区分列表...我
{{{{{}}}}} or {{} {} {} {}}, and so on ...
我的方法只是编写一个函数,在给定的层次上递归到每个列表的底部,并且如果有东西存在,则设置一个标志。
我的问题是,尽管阅读文档,调用下面:
proc IsNestedEmpty {i_list} {
if {[string is list $i_list]} {
puts "it was a list"
} else {
puts "it was not a list"
}
}
isNestedEmpty 1
isNestedEmpty ""
isNestedEmpty "jifjsfjsk"
isNestedEmpty [list 1 2 3]
我得到的输出:
it was a list
it was a list
it was a list
it was a list
TCL的版本我已经是8.5 检查文档中, -strict标志不会有帮助(并且测试它是真实的) - 有其他方法可靠地检查我拥有的是列表吗? (因为如果我遍历一个实际上是整数的“列表”,比如说,我将只返回整数并结束无限循环)
编辑:鉴于字符串不会帮助我......我有一个思想,并似乎有更多的运气...
proc IsNestedEmpty {i_list {isEmpty 1}} {
if {$isEmpty} {
foreach el $i_list {
if {$el == $i_list} {
if {$el != ""} {
return 0
}
} else {
set isEmpty [IsNestedEmpty $el $isEmpty]
}
}
}
return $isEmpty
}
仍在试图打破它,但
puts [IsNestedEmpty {{{{"" ""}} "" "" {{{{}}}} } {} {} {} {{{{} {} {} 4}}}}]
puts [IsNestedEmpty {{{{"" ""}} "" "" {{{{}}}} } {} {} {} {{{{} {} {} }}}}]
给我0和1分别
我不知道这是否会帮助,但你可以拿上tcllib挤图书馆看看 – Leo 2014-09-18 17:36:34
感谢那,因为我怀疑我能够使用那个库,我最终会使用这个函数来使用这个函数 - 我只限于我自己写的任何东西。 – HexedAgain 2014-09-18 18:06:51
看看我更新的答案。 – 2014-09-18 19:54:06