|
From: Dipl. I. S. G. B. <se...@us...> - 2017-02-14 17:28:04
|
The answer is - will be then impossible, but...
But let me ask you: how often you'll use such array keys?
Why this should run within assignment in expression implicitly?
Exactly the case that I meant (where index is calculated) may be wanted
in expression, because it prevents got out to calculate the index.
Your (IMHO very "artificial") case can be used directly with [set a(1+1)
...], then you'll prevent calculate 1+1.
And if it will be a content of variable, then it will be not substituted
twice.
So `set k "1+1"; expr { a($k) = 42 }` will set array value of index
'1+1'.
Regards,
sebres.
Am 14.02.2017 18:12, schrieb Peter S:
> On 14/02/2017, Dipl. Ing. Sergey G. Brester
> <se...@us...> wrote:
>
>> I'll try to explain it on `expr {a($i + $k) = 42}` The algorithm would be:
>
> [...]
>
>> - if we have it - a(expr1) is an array variable
>
> So, if I understand right, your suggestion would treat '$i + $k' as a
> sub-expression, and evaluate it, so say if $i = 1 and $k = 1, then the
> above line would set 'a(2) = 42'.
>
> With this scheme, how would it be possible to set the literal array
> index '1+1' ? Would the index need to be quoted to escape evaluation
> as expression?
>
> a) expr { a({1+1}) = 42 } ;# set index '1+1' to 42
> b) expr { a("1+1") = 42 } ;# set index '1+1' to 42
>
> If so, then every array index that is not an expression (that includes
> every bareword), would need to be quoted...
>
> --Peter
|