等价于tcl中的#define? [英] Equivalent of #define in tcl?
问题描述
tcl中是否有一个等效于C ++ #define的命令?我已经看到了使用proc函数重载来实现定义的方法,只是想知道是否有人知道更省钱的方法
Is there a command in tcl that is equivalent to C++ #define? I've seen ways to implement "define" using overloading of the proc function, just wanted to know if anyone knows of a more starightforward way
推荐答案
Tcl具有一种机制,可让您定义别名为过程在翻译中。
Tcl has a mechanism that lets you define aliases to procedures in an interpreter.
如果您有
proc foo {one two three} {do something with $one $two $three}
,您会发现自己总是在传递$ a和$ b作为前两个参数,您可以编写:
and you find you're always passing $a and $b as the first two arguments, you can write:
interp alias {} foo_ab {} foo $a $b
现在您可以说:
foo_ab $d ;# same as "foo $a $b $d"
foo_ab $e ;# same as "foo $a $b $e"
示例:
proc foo {one two three} {puts [join [list $one $two $three] :]}
set a Hello
set b World
interp alias {} foo_ab {} foo $a $b
foo_ab example ;# prints "Hello:World:example"
interp别名
命令仅表示当前的解释器。您可以使用从属解释器来做很多有趣的事情。
The empty braces in the interp alias
command merely signify the current interpreter. You can do lots of fun things with slave interpreters.
这篇关于等价于tcl中的#define?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!