czchlong
czchlong

Reputation: 2574

Tcl procedure cannot read variable passed in by another procedure

I have a Tcl procedure that wraps around another procedure and passes it some arguments, like so:

proc OuterProc {
  ...some code here...
  InnerProc $a $b
}

proc InnerProc { a, b } {
  set someVar1 [split $a]
  set someVar2 [split $b]
  ...error: cannot read variable a or b
}

Why can't the InnerProc see the 2 arguments being passed in?

Thanks

Upvotes: 1

Views: 344

Answers (1)

glenn jackman
glenn jackman

Reputation: 246744

The problem as shown in the question, is you have a comma in your argument list. Note that Tcl generally uses whitespace to separate arguments, not commas.

proc OuterProc {} {
    set x foo
    set y bar
    InnerProc $x $y
}
proc InnerProc {a b} {
    puts "a=$a"
    puts "b=$b"
}
OuterProc

produces

a=foo
b=bar

I've used different variable names in the OuterProc procedure to demonstrate that is does not matter what your local variable names are, Tcl will pass the values to the next proc.

If that is not your problem, then you need to show us more specifically what your real code is.

Upvotes: 4

Related Questions