From: Gerhard Reithofer on
Hi all,

On Thu, 19 Nov 2009, Bryan Oakley wrote:

> On Nov 19, 10:22 am, Gerhard Reithofer <gerhard.reitho...(a)tech-
> edv.co.at> wrote:
> > Hi TCLers,
> > I've studied Tcl language syntax several times, but I don't see my
> > fault:
> >
> > % set obrace 3
> > 3
> > % if {$obrace<0} {return "missing '}'"}
> > extra characters after close-brace

....

> First word: if
> second word: {$obrace<0}
> third word: {return "missing '}
>
> immediately after that closing brace of the third word is the
> character ', hence the error message.
>
> Remember: when a word starts with a brace it continues to the closing
> brace, and double quotes are ignored with the opening and closing
> brace.

thanks, it really was the "common Tcl syntax blindness" ;)

But what about the following:
if {$o eq "{"} {puts "doesn't work"}

Word 1: if
Word 2: {$c eq "{"}
Word 3: {puts "doensn't work"}

If I interprete that correct, is any double quote ignored within
braces - therefore the "matching" closing brace is missing.

A few solutions:
if { $o eq "\{" } {puts "1 works"}
if [expr { $o eq "\{" }] {puts "2 works"}
if {[expr { $o eq "\{" }]} {puts "3 works"}
if [expr \"$o\" eq \"{\" ] {puts "4 works"}

In other words, it is necessary to quote ANY brace within a braced
block, the only exception is a single command without braces (see 4.)

puts "{ is ok"
if 1 {puts "{ is not"}

--
Gerhard Reithofer
Tech-EDV Support Forum - http://support.tech-edv.co.at
From: Ronnie Brunner on
Gerhard Reithofer wrote:
> But what about the following:
> if {$o eq "{"} {puts "doesn't work"}
>
> Word 1: if
> Word 2: {$c eq "{"}
> Word 3: {puts "doensn't work"}

Nope:
Word 1: if
Word 2: <not complete>

Rule [6] again: "Braces nest within the word: for each additional open
brace there must be an additional close brace [...]" which is not the
case for your '{' in double quotes

if {$o eq "\{"} {puts "works"}

is what you want

> In other words, it is necessary to quote ANY brace within a braced
> block, the only exception is a single command without braces (see 4.)

Nope, as long as they are matched: no need to escape them

if {$o eq "{}"} {puts "works too"}

hth
Ronnie
--
Ronnie Brunner | ronnie.brunner(a)netcetera.ch
phone +41-44-247 79 79 | fax +41-44-247 70 75
Netcetera AG | 8040 Z�rich | Switzerland | http://netcetera.ch
From: Gerhard Reithofer on
On Fri, 20 Nov 2009, Ronnie Brunner wrote:
> Gerhard Reithofer wrote:
> > But what about the following:
> > if {$o eq "{"} {puts "doesn't work"}
> >
> > Word 1: if
> > Word 2: {$c eq "{"} Word 3: {puts "doensn't work"}
>
> Nope:
> Word 1: if
> Word 2: <not complete>
>
> Rule [6] again: "Braces nest within the word: for each additional open brace
> there must be an additional close brace [...]" which is not the case for your
> '{' in double quotes
>
> if {$o eq "\{"} {puts "works"}
>
> is what you want
>
> > In other words, it is necessary to quote ANY brace within a braced block,
> > the only exception is a single command without braces (see 4.)
>
> Nope, as long as they are matched: no need to escape them
>
> if {$o eq "{}"} {puts "works too"}

ACK
I thought of the typical single braces (e.g. for parsing, ...)

THX
--
Gerhard Reithofer
Tech-EDV Support Forum - http://support.tech-edv.co.at