Deutsch English Français Italiano |
<vs0sbr$1ovrs$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Alan Grunwald <nospam.nurdglaw@gmail.com> Newsgroups: comp.lang.tcl Subject: Re: can this work? Date: Wed, 26 Mar 2025 12:35:07 +0000 Organization: A noiseless patient Spider Lines: 81 Message-ID: <vs0sbr$1ovrs$1@dont-email.me> References: <vrjsse$1oane$1@dont-email.me> <20250321163420.39ecbc0b40151daab77dcc27@domain.invalid> <vrkkeq$2c2m0$1@dont-email.me> <vrkqq1$2hm9c$1@dont-email.me> <vrmbb6$3vamk$1@dont-email.me> <vrmjv9$6fer$1@dont-email.me> <vs00fd$10bgm$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 26 Mar 2025 13:36:12 +0100 (CET) Injection-Info: dont-email.me; posting-host="6769cf6f828733de3bdee47e54b22b1c"; logging-data="1867644"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cKhJrEnK9eu5BUfBEFHBfvl55sCO+J6I=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:4VSGiG6P2e9A6m1LSLzfKUw9+Ss= In-Reply-To: <vs00fd$10bgm$1@dont-email.me> Content-Language: en-US Bytes: 3689 On 26/03/2025 04:40, et99 wrote: > 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 :) > > > > > FWIW, I remember when I first started to use [expr {$a eq "b"}] if took me *AGES* to get the syntax right. To be fair to [expr], its error message (if you omit the double-quotes) is pretty specific, but I still found it a struggle to get the syntax right. The lesson I took from this was to stop writing set i foo and to start writing set i "foo" but the temptation to save a couple of keystrokes is still strong :-)