传递列表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
是等效的。
我相信,我以前看到这一点,但我不能在网上任何地方找到它。任何帮助(和code)就等同的情况下都将是AP preciated。
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及以下:
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屋!
查看全文