Using $variable in Parenthesis in Tcl (proc)

484 Views Asked by At

A part of my code in tcl is:

proc Frame {columnLine} {
.
.
.
}

Now I want use $variable in parenthesis. For example:

set x 2.
set columnLine {$x 5. 10. 15.}

However, after running Tcl, I face an error! How I do solve this problem?

1

There are 1 best solutions below

0
On BEST ANSWER

Tcl does not do substitutions on things inside {braces}. If you want substitutions, you've got to either put the overall word inside "double quotes", or use the subst command:

set x 2.
set columnLine [subst {$x 5. 10. 15.}]
set x 2.
set columnLine "$x 5. 10. 15."

One advantage of using subst is that you can pick to just substitute variables and leave backslashes and [bracketed command calls] alone. This is sometimes very useful indeed.

set x 2.
set columnLine [subst -nobackslashes -nocommands {$x 5. 10. 15.}]