how to pass variable arguments from one function to other in tcl

Posted by vaichidrewar on Stack Overflow See other posts from Stack Overflow or by vaichidrewar
Published on 2010-12-30T06:59:45Z Indexed on 2010/12/31 16:53 UTC
Read the original article Hit count: 177

Filed under:
|

I want to pass variable arguments obtained in one function to other function but I am not able to do so. Function gets even number of variable arguments and then it has to be converted in array. Below is the example.

Procedure abc1 gets two arguments (k k) and not form abc1 procedure these have to be passed to proc abc where list to array conversion it to be done. List to array conversion works in proc1 i.e. abc1 but not in second proc i.e. abc

Error obtained is given below

proc abc {args} {
    puts "$args"
    array set arg $args
}

proc abc1 {args} {
    puts "$args"
    array set arg $args
    set l2 [array get arg]
    abc $l2
}

abc1 k k
abc k k

Output:

k k
{k k}
list must have an even number of elements
    while executing
"array set arg $l1"
    (procedure "abc" line 8)
    invoked from within
"abc $l2"
    (procedure "abc1" line 5)
    invoked from within
"abc1 k k"
    (file "vfunction.tcl" line 18)

© Stack Overflow or respective owner

Related posts about tcl

Related posts about variableargumentlists