As I've mentioned a few times previously, I know very little about TCL and TCL syntax, even though I've been using (coding in) Expect for many
decades. I've learned what little TCL I need through lots of
trial-and-error and I've asked questions on this NG from time-to-time.
That said, I noticed that the following works as expected:
% puts { This is a string { with embedded curly braces } and it actually works }
This is a string { with embedded curly braces } and it actually works
%
So, it looks like the parser looks inside the outer { } and parses the
inner { } construct. This is good in a way, but is scary, when you start
to consider the possibilities. It means that { } in TCL is not quite as
easy to understand as is the single quote mechanism (known as "strong quoting") in the shell (sh or bash). In the shell, literally the only
thing that is magic inside of ' is '. And you can always get a ' inside of
a single-quoted string by doing:
$ echo 'Don'\''t do that!'
As far as I can tell, it is not possible to do the analogous thing in TCL.
Note that the following variation on the above does not work:
% puts { This is a string with a right curly brace } that does not work } (error message)
%
I could not figure out how to display the later string in a way that
doesn't error out. So, my question is: How to do that?
Note, BTW:
% puts { This is a string with a right curly brace \} that does work }
This is a string with a right curly brace \} that does work
%
Except that you get that stray backslash in the output - that you
presumably don't want there.
Note that the following variation on the above does not work:
% puts { This is a string with a right curly brace } that does not work } (error message)
%
I could not figure out how to display the later string in a way that
doesn't error out. So, my question is: How to do that?
* Harald Oehlmann <wortkarg3@yahoo.com>
| So, to represent a string with a non-balanced "{", you need:
| puts " This is a string with a right curly brace } that does not work "
| In the context of a opened curly brace, like a program fragment, it is
| necessary to escape the curly brace:
IMHO escaping an unmatched curly is good practice even in cases where it
is not strictly necessary.
On 2/18/2026 11:14 AM, Ralf Fassel wrote:
* Harald Oehlmann <wortkarg3@yahoo.com>
| So, to represent a string with a non-balanced "{", you need:
| puts " This is a string with a right curly brace } that does not work "
| In the context of a opened curly brace, like a program fragment, it is
| necessary to escape the curly brace:
IMHO escaping an unmatched curly is good practice even in cases where it
is not strictly necessary.
Curious. Do you have an example where it is not needed but it doesn't
hurt to use it?
Am 18.02.2026 um 17:57 schrieb saito:
On 2/18/2026 11:14 AM, Ralf Fassel wrote:
* Harald Oehlmann <wortkarg3@yahoo.com>
| So, to represent a string with a non-balanced "{", you need:
| puts " This is a string with a right curly brace } that does not
work "
| In the context of a opened curly brace, like a program fragment, it is >>> | necessary to escape the curly brace:
IMHO escaping an unmatched curly is good practice even in cases where it >>> is not strictly necessary.
Curious. Do you have an example where it is not needed but it doesn't
hurt to use it?
See my example in my post ;-)
Note that the following variation on the above does not work:
% puts { This is a string with a right curly brace } that does not work }
(error message)
%
I could not figure out how to display the later string in a way that
doesn't error out. So, my question is: How to do that?
By changing the starting/ending characters to the " which does
interpret backslash (but also interprets $ and [ too):
$ rlwrap tclsh
% puts " This is a string with a right curly brace \} that does not work "
This is a string with a right curly brace } that does not work
Read this wiki page very carefully, pay special attention to the
portion under the "Rules" heading:
https://wiki.tcl-lang.org/page/Dodekalogue
The items under the Rules heading fully define Tcl's syntax. But,
fully internalizing them does take some effort.
In article <10n4ic2$2m8ri$3@dont-email.me>, Rich <rich@example.invalid> wrote:
Kenny McCormack <gazelle@shell.xmission.com> wrote:
Note that the following variation on the above does not work:
% puts { This is a string with a right curly brace } that does not work } >>> (error message)
%
I could not figure out how to display the later string in a way that
doesn't error out. So, my question is: How to do that?
By changing the starting/ending characters to the " which does
interpret backslash (but also interprets $ and [ too):
Actually, I'm quite familiar with using " instead of {, but generally, one should want to use the strong quoting rather than weak quoting. When I
first started using TCL, I tended to use " for strings, primarily because I was familiar with it from shell. But then I worked out that with ", you ended up having to escape [ all the time and that gets to be a pain. It is particularly hard to use " when using reg exps, because of the need for quoting.
So, it seems like what you really want is the equivalent of the shell's single quote (aka, "strong quoting"), where you don't have to quote
anything, except for the single quote itself - where if you want a single quote, you put '\''. So, long and short of this, I was surprised to find that in TCL, inside of {}, you still have to be careful with } and that, as far as I can tell, there's no way to do the example shown in the OP.
Yes, I get it that if you switch to using " instead of {}, then the }
problem goes away, but then you have to escape everything else. Ugly.
BTW, I should also note that many of my posts (to various newsgroups and support boards) - including this one - have the form of:
Yes, I have already figured out the answer/workaround, but I'm amazed
and amused that it is the way it is. My question boils down to "Is it
really as whack as I think it is?" and the answer usually ends up being
"Yes".
$ rlwrap tclsh
% puts " This is a string with a right curly brace \} that does not work " >> This is a string with a right curly brace } that does not work
Read this wiki page very carefully, pay special attention to the
portion under the "Rules" heading:
https://wiki.tcl-lang.org/page/Dodekalogue
The items under the Rules heading fully define Tcl's syntax. But,
fully internalizing them does take some effort.
Clearly so. It's weird.
The items under the Rules heading fully define Tcl's syntax. But,
fully internalizing them does take some effort.
Clearly so. It's weird.
puts "here is a string with a \{" ;# this will work here }
if { 1 } {
-a-a-a-aputs "here is a string with a \{" ;# watch out here }
} else {
-a-a-a-aputs "can't happen"
}
On 2/18/2026 3:56 PM, et99 wrote:
puts "here is a string with a \{" ;# this will work here }
if { 1 } {
-a-a-a-aputs "here is a string with a \{" ;# watch out here }
} else {
-a-a-a-aputs "can't happen"
}
I said that incorrectly. This will fail when it gets to the } else {
since the brace in the comment ends the if block and it thinks } else
{ is a new command.
On 2/18/2026 3:56 PM, et99 wrote:
puts "here is a string with a \{" ;# this will work here }
if { 1 } {
-a-a-a-a-aputs "here is a string with a \{" ;# watch out here }
} else {
-a-a-a-a-aputs "can't happen"
}
I said that incorrectly. This will fail when it gets to the } else
{ since the brace in the comment ends the if block and it thinks } else
{ is a new command.
Am 19.02.2026 um 01:02 schrieb et99:
On 2/18/2026 3:56 PM, et99 wrote:
puts "here is a string with a \{" ;# this will work here }
if { 1 } {
-a-a-a-a-aputs "here is a string with a \{" ;# watch out here }
} else {
-a-a-a-a-aputs "can't happen"
}
I said that incorrectly. This will fail when it gets to the } else
{ since the brace in the comment ends the if block and it thinks }
else { is a new command.
Yes, we are sorry for this. TCL does not make any difference between comments and commands. Due to that, non balances "{" in comments will
change the organisation of your file.
So, the upper snippet is identical to the following code:
if { 1 } {
-a-a-a-a-a puts "here is a string with a \{" ;# watch out here
}
} else {
-a-a-a-a-a puts "can't happen"
}
This is often hard to understand.
The background is, that there is no difference between code and strings.
And the "{}" do general grouping. They are often handy in programming,
but not necessary.
if " 1 " "
-a-a-a puts "here is a string with a \{" ;# watch out here }
" else "
-a-a-a-a-a puts "can't happen"
"
would work in your case. Nevertheless, never do this without clear
reasons, e.g. when you construct program code.
For example:
if $cond $cmdyes else $cmdno
Sorry, it gets complicated....
I just want to say:
- yes, this is on purpose
- there are use-cases (constructed code), where this is quite handy.
Perhaps, others have better examples...
Thanks,
Harald
Am 19.02.2026 um 09:53 schrieb Harald Oehlmann:
Am 19.02.2026 um 01:02 schrieb et99:
On 2/18/2026 3:56 PM, et99 wrote:
puts "here is a string with a \{" ;# this will work here }
if { 1 } {
-a-a-a-a-aputs "here is a string with a \{" ;# watch out here }
} else {
-a-a-a-a-aputs "can't happen"
}
I said that incorrectly. This will fail when it gets to the } else { since the brace in the comment ends the if block and it thinks } else { is a new command.
Yes, we are sorry for this. TCL does not make any difference between comments and commands. Due to that, non balances "{" in comments will change the organisation of your file.
So, the upper snippet is identical to the following code:
if { 1 } {
-a-a-a-a-a-a puts "here is a string with a \{" ;# watch out here
}
} else {
-a-a-a-a-a-a puts "can't happen"
}
This is often hard to understand.
The background is, that there is no difference between code and strings.
And the "{}" do general grouping. They are often handy in programming, but not necessary.
if " 1 " "
-a-a-a-a puts "here is a string with a \{" ;# watch out here }
" else "
-a-a-a-a-a-a puts "can't happen"
"
would work in your case. Nevertheless, never do this without clear reasons, e.g. when you construct program code.
For example:
if $cond $cmdyes else $cmdno
Sorry, it gets complicated....
I just want to say:
- yes, this is on purpose
- there are use-cases (constructed code), where this is quite handy.
Perhaps, others have better examples...
Thanks,
Harald
Sorry, my example was wrong, the " is closed at the string start.
Anyway, others may give examples.
A typical way to construct code is to use a list
set Cmd [list if $cand $cmdyes else $cmdno]
eval $Cmd
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 03:45:22 |
| Calls: | 812 |
| Files: | 1,287 |
| D/L today: |
1 files (3,740K bytes) |
| Messages: | 210,189 |