将列表传递给 Tcl 过程 [英] Passing list to Tcl procedure
本文介绍了将列表传递给 Tcl 过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将列表传递给 Tcl 过程的规范方法是什么?
What is the canonical way to pass a list to a Tcl procedure?
如果我能得到它,我真的很喜欢它,以便将列表自动扩展为可变数量的参数.
I'd really like it if I could get it so that a list is automatically expanded into a variable number of arguments.
所以类似:
set a {b c}
myprocedure option1 option2 $a
和
myprocedure option1 option2 b c
是等价的.
我确定我以前看过这个,但我在网上找不到它.任何使这两种情况等效的帮助(和代码)将不胜感激.
I am sure I saw this before, but I can't find it anywhere online. Any help (and code) to make both cases equivalent would be appreciated.
这是否被认为是标准的 Tcl 约定.或者我什至吠错了树?
Is this considered a standard Tcl convention. Or am I even barking up the wrong tree?
推荐答案
这取决于您使用的 Tcl 版本,但是:对于 8.5:
It depends on the version of Tcl you're using, but: For 8.5:
set mylist {a b c}
myprocedure option1 option2 {*}$mylist
对于 8.4 及以下:
For 8.4 and below:
set mylist {a b c}
eval myprocedure option1 option2 $mylist
# or, if option1 and 2 are variables
eval myprocedure [list $option1] [list $option2] $mylist
# or, as Bryan prefers
eval myprocedure \$option1 \$option2 $mylist
这篇关于将列表传递给 Tcl 过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文