Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the usage of braces

Tags:

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?

like image 372
jack the lesser Avatar asked Feb 03 '10 16:02

jack the lesser


People also ask

How do you use braces grammar?

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.

What are {} used for?

In writing, curly brackets or braces are used to indicate that certain words and/or sentences should be looked at as a group.

What are the brackets for in braces?

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.

How many brackets are there in braces?

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.


1 Answers

In a nutshell,

  • Tcl's braces act like sh's single quotes -- group words (and lines) without interpolation.
  • Tcl's double quotes act like sh's double quotes -- allowing interpolation.

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.

like image 197
glenn jackman Avatar answered Sep 19 '22 01:09

glenn jackman