发新话题
打印

[求助] tcl中的proc可变参数问题

tcl中的proc可变参数问题

如果proc中的最后一个参数为args,那么表示这个proc支持可变个数的参数。如果一个参数都没输入的话,args的值应该是什么?空串么?
7 F" m7 r4 @0 \2 D' u5 v3 s: E  j下面有一个例子,不明白为什么输入0或1个参数的时候,argc的值都为1。
) D' u) a" q+ D$ w, `( _. D程序为:9 b1 H' M! v! I& h- e
proc create_schematic { args } {6 w+ s( {! x. \2 l8 j: e, o
    * D1 [' }. b2 m) Z
    set argc [ llength args ]
1 F2 H1 E4 i0 `# M' T- b% T    puts "DEBUG: argc -> $argc"  v" A$ U& `* k  u) F
    puts "DEBUG: args -> $args,"
" ~) F. o' G* b. d+ A" M" d}
" T. c* u/ z$ L) \' H$ }: hcreate_schematic
/ E! O7 w9 j" y: wcreate_schematic aaa$ F3 D) D8 S; ?1 T- N
输出为:
2 c4 W/ a' U1 wDEBUG: argc -> 11 G% }, U# D2 B1 j( x1 f
DEBUG: args -> ,
. t: D( l. I+ b$ a- s# ZDEBUG: argc -> 13 X0 J( M* i2 N
DEBUG: args -> aaa,

TOP

呵呵,知道原因了,应该是set argc [ llength $args ]

TOP

刚看见,就被你自己给回了,没抢到。
With your idea, Carry out together.

TOP

发新话题