|
From: Phillip B. <phi...@um...> - 2025-10-21 00:33:45
|
Thanks for the explanation. Yes, I did try to run both commands
together. I see what is going on with that statement now. I was unaware
of the possibility of having an unnamed array previously.
Regarding my Tcl version, I am running vanilla 9.1 of a fairly recent
vintage, but also tried using 8.5.
Regarding the double parenthesis expression proposal, I'm not sure that I
follow you. Is there a way to use the single argument set command to
create an ambiguity between $(( expression )) as an arithmetic expression
evaluator and some existing code using an unnamed array, or set (or any
other currently legal syntax)? Since that command doesn't involve the $
character, I don't see how it gets in the way. If you can think of one,
can you write a couple of lines of code that illustrate it?
Phil
On Mon, Oct 20, 2025 at 5:07 PM EricT <tw...@gm...> wrote:
> I believe the reason you got the error was that you actually typed both
> statements, setting the scalar null variable and then tried the array null
> variable.
>
> However, I believe the problem is that you are running into some parser
> issues here that the manual doesn't mention. It does, however, say
>
> Note that variables may contain character sequences other than those
> listed above, but in that case other mechanisms must be used to access them
> (e.g., via the *set *command's single-argument form).
>
> And so that is why the above using set does return the value 5. But when
> trying $ substitution, the rules are more restrictive, and you likely hit
> one of the edge cases here.
>
> Eric
>
>
> On Mon, Oct 20, 2025 at 4:30 PM Phillip Brooks <phi...@um...> wrote:
>
>> Let me try making my previous email a little more concise since it hasn't
>> generated any follow-ups.
>>
>> 1) Is there a bust in the TIP 672 example code. I can't run this code
>> from the TIP:
>>
>> set {} foobar ;# scalar variable
>>
>> set (index) "array value" ;# array variable
>>
>> When I run that, I get:
>>
>> can't set "(index)": variable isn't array
>>
>>
>> Please explain.
>>
>> 2) The bash shell uses the syntax $(( expression )) for arithmetic. Does
>> that syntax solve the problem of the unnamed array ambiguity that $(
>> expression ) introduces? The $(( expression )) syntax, at least in my
>> small example, seems illegal. I am only testing this out on a simple case
>> I tried after the above code didn't work:
>>
>> % array set {} { 2+2 5 }
>>
>> % puts $(2+2)
>>
>> 5
>>
>>
>> The above code illustrates the problem with $(2+2) being interpreted as
>> an index into the unnamed array. If I try doing that with an extra ( in
>> the expression, it is invalid syntax:
>>
>> % array set {} { (2+2) 5 }
>>
>> % puts $((2+2))
>>
>> invalid character in array index
>>
>>
>> To get at the array element named (2+2), you have to add escape
>> characters:
>>
>>
>> % puts $(\(2+2\))
>>
>> 5
>>
>>
>> It seems to me that if $(( expression )) works generally, it has several
>> advantages:
>>
>> - it is easier to read and type than {=}{ expression }. (While {=}
>> adds only two characters, { and } are shifted, = is unshifted which makes
>> for much slower typing.)
>> - it has precedent in bash
>> - it doesn't overload the meaning of preexisting valid syntax.
>>
>> Are there other issues with $(( expression )) that I don't know of?
>> Please explain?
>>
>> Phil
>> _______________________________________________
>> Tcl-Core mailing list
>> Tcl...@li...
>> https://lists.sourceforge.net/lists/listinfo/tcl-core
>>
>
|