I'm learning Tcl/Tk and am confused on the usage of curly braces in tcl.
To me it seems to be used to both indicate scope and declare strings! Is this a bug (or feature)?
Is my interpretation correct?
Braces are always used in pairs As with other types of brackets, it is considered a grammatical error to only use a single brace. Braces are typically used in pairs: ❌ Incorrect: The numbers on the sign {7, 2, 6, 3, 5 were hard to read.
In writing, curly brackets or braces are used to indicate that certain words and/or sentences should be looked at as a group.
Brackets are the small metal squares that are attached to the front and side teeth. They act like handles that allow us to grab onto the teeth to move them. They are bonded directly to the enamel of the tooth with a special adhesive. Brackets are made of stainless steel.
Here are three general bracket types. A tube bracket – on the left. A twin bracket in the middle. A self-ligation bracket on the right.
In a nutshell,
The fact that you use curly braces in a proc
definition is not mandatory. It's just the most convenient way to pass a script as an argument to proc without interpolating.
These are equivalent
proc add3 {a b c} { return [expr {$a + $b + $c}] }
and
proc add3_weird [list a b c] "return \[expr {\[set a] + \[set b] + \[set c]}]"
Once you internalize Tcl quoting, you'll realize how truly flexible Tcl can be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With