Sujet : Re: can this work?
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tclDate : 26. Mar 2025, 05:40:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vs00fd$10bgm$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
On 3/22/2025 8:11 AM, Rich wrote:
--snip--
The for command is defined as always running expr on the middle
argument. Whether you get a loop that looks up variable contents by
that expr call to make the check dynamic, or a loop that runs expr on
the exact same static values for each iteration, depends upon what you
pass to the command. That depends upon what you write that is parsed
by the Tcl parser.
Actually, the manual for the [for] command does not say it runs [expr], rather, it only says:
Then it repeatedly evaluates test as an expression;
And the command [expr] is not mentioned at all. Also, in the page with the 12 rules, it never defines the word expression.
The [if] command, however, does mention the use of [expr]:
The if command evaluates expr1 as an expression (in the same way that expr evaluates its argument).
I suppose one has to get deep into the weeds and fully understand the algorithm of [expr] to be able to parse it all. There, [expr] does define an expression.
One item that took me forever to understand is why in most commands, words such as in these 3,
set foo bar
set foo {bar}
set foo "bar"
the 2 types of quotes don't change the result here from the unquoted version. But in [expr] and therefore also in the first argument to [if] and the second to [for] a string has to be quoted in one of the 2 ways. So that,
if {$foo eq "bar"} ..
if {$foo eq {bar}} ..
is ok, but
if {$foo eq bar} ..
is not ok. And the reason is that,
expr {$foo eq bar}
also produces an error since operands in [expr] are not the same as tcl words. Here, [expr] complains about a bare word - something I've also not seen defined.
Anyway, there's always something to learn here :)