|
From: Phillip B. <phi...@um...> - 2025-10-20 23:29:51
|
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
|