Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Optimization of getarrvalue()



On 2016/11/17, at 3:50, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 
> It would be more accurate to say "accesses to an array element with a
> subscript that evaluates to zero behave in the same way as accesses to
> any unset scalar parameter."

Maybe, but I still don't understand, for example, the following:

% a=()
% nargs "${(@)a[0]}"
1
% a=( foo )
% nargs "${(@)a[0]}"
0

But anyway zero is "special" and treating it specially may be OK.

My main concern was, for example,

% a=( foo bar )
% nargs "${(@)a[3]}"
1
% nargs "${(@)a[3,3]}"     # or "${(@)a[3,4]}"  "${(@)a[3,5]}" ...
0

More generally, $a[i,j] with i=$#a+1 is treated specially.

For a=(), treating i=j=1 specially is necessary for RC_EXPAND_PARAM
to work correctly. But for non-empty array, it may be possible to
make i=$#a+1 behave similarly as other out-of-range values.
But maybe it is not worth doing if no one is complaining about this.



Messages sorted by: Reverse Date, Date, Thread, Author