Reputation: 13
I am trying to perform a variable substitution within curly braces which I understand is not feasible directly in TCL.
The code I am trying:
interface code -clip {$x1 $y1 $x2 $y2}
The interface code is a third party TCL function that has an option called clip which reads x1,y1,x2,y2 coordinates within curly braces.
I need to feed in the values of x1,y2 within the curly braces.
Upvotes: 1
Views: 9283
Reputation: 137567
In Tcl, the {…}
syntax technically means “do no substitutions at all on this”. The command that the value gets passed to might do its own thing with those characters, and those things might look a lot like substitution (e.g., if it is evaluating the word as a script, which is what if
and for
and while
and … do), but Tcl's core syntax just leaves them alone and passes them through.
To get what you want, there's a few alternatives. You can do the substitutions before passing the value in — the command literally can't see that you've done this if you choose to do it — or you can get the command to do the substitutions (not a useful suggestion if it's third-party code, of course).
To do the substitutions yourself, you might do one of these:
interface code -clip [list $x1 $y1 $x2 $y2]
interface code -clip "$x1 $y1 $x2 $y2"
interface code -clip [subst {$x1 $y1 $x2 $y2}]
The first option is good if the command takes a list (which your case looks like; it appears to be a coordinate list). The second option is good if the command takes a string. The third option is good when things are getting complicated! It's usually a good idea to try to avoid very complicated stuff; programs are difficult enough to write and read without deliberately making them even harder to understand.
Upvotes: 6