Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: RFC PATCH: Sketch at :@ subscripting
- X-seq: zsh-workers 48387
- From: Lawrence Velázquez <vq@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: RFC PATCH: Sketch at :@ subscripting
- Date: Sat, 03 Apr 2021 15:48:03 -0400
- Archived-at: <https://zsh.org/workers/48387>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-04/a18478fe-6118-42c4-948d-3bd99db2875d%40www.fastmail.com>
- In-reply-to: <CAH+w=7aRG1dfB5yAQ6yKV-GeHY7R_zWveHMU4+8QWNU9qSYkFA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20201218131815.25999-1-mikachu@gmail.com> <20201219091314.dxslsscyiqffa3il@chazelas.org> <CAH+w=7aRG1dfB5yAQ6yKV-GeHY7R_zWveHMU4+8QWNU9qSYkFA@mail.gmail.com>
On Sat, Mar 27, 2021, at 4:27 PM, Bart Schaefer wrote:
> On Sat, Dec 19, 2020 at 1:13 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> >
> > 2020-12-18 14:18:15 +0100, Mikael Magnusson:
> > [...]
> > > The idea is that you can do this:
> > > % typeset -a somearray=( 'data here' 'some words' etc etc 1 2 3 4 ) idx=(1 3 5)
> > > % echo ${somearray:@idx}
> > > data here etc 1
> > [...]
> >
> > Hi Mikael,
> >
> > I can't help but think that allowing to specify the indexes
> > directly as perl does for instance in:
> >
> > print @list[1, 4, 2, 7..10, @idx, -1];
>
> The way to do this (syntactically speaking) would be with a subscript
> flag. E.g.:
> print $array[(^)1,3,7]
> would change the interpretation of the commas to select a set of
> elements instead of a range. I chose (^) because of symmetry with
> $^array and to avoid confusion with for example $array[@].
>
> I haven't looked into how difficult that might be to implement,
> particularly in assignment context.
>
> Another possibility is to handle $array[{1,3,7}] specially since "{"
> is already a syntax error in math context.
>
> Both of those options could apply to associative arrays, although keys
> would need to respect quoting to avoid troubles with an embedded ",".
>
> > $ i=1,3
> > $ echo ${a[i]}
> > c
>
> Here [i] is interpreted in math context so the comma becomes an
> operator (the collision you already noted) so this becomes $a[3]
>
> > $ echo ${a[$i]}
> > a
>
> This one is confusing and a bug ... it should be the same as
> ${a[$[$i]]} but instead it's ${a[,3]}. I haven't tracked down exactly
> what's skipping everything up to but not including the first comma (it
> is not, for example, just dropping one character).
bump
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author