TCL (we're on 7.6) has a special variable name "args" for variable
arguments.  It seems to work fine for 1 level, but I'm confused if/how
it can be used for multiple procedure levels since it "listifies" its
argument on every procedure call.

For example, in this test program, passing "args" to lower level
procedures keeps modifying the argument, but I really want it to stay
the same:

proc xyzzy0 {arg1 args} {
  return "
arg1=$arg1
args=$args
llength=[llength $args]
1st el=[lindex $args 0]
"
}

proc xyzzy1 {arg1 args} {
  return [xyzzy0 $arg1 $args]
}

proc xyzzy2 {arg1 args} {
  return [xyzzy1 $arg1 $args]
}

ns_return 200 text/plain "
xyzzy0: [xyzzy0 a1 "a2 a3" "a4 a5"]

xyzzy1: [xyzzy1 a1 "a2 a3" "a4 a5"]

xyzzy2: [xyzzy2 a1 "a2 a3" "a4 a5"]
"
return


Here's the output:

xyzzy0:
arg1=a1
args={a2 a3} {a4 a5}         --- this one is what I expected
llength=2
1st el=a2 a3


xyzzy1:
arg1=a1
args={{a2 a3} {a4 a5}}
llength=1
1st el={a2 a3} {a4 a5}


xyzzy2:
arg1=a1
args={{{a2 a3} {a4 a5}}}
llength=1
1st el={{a2 a3} {a4 a5}}


Is there a way to "unlistify" $args before passing it to a lower level
proc?  Or is there a better/right way to do this?

Any advice appreciated.

Jim

Reply via email to