From: "Lawrence Velázquez" <vq@larryv.me>
To: zsh-workers@zsh.org
Subject: Re: RFC PATCH: Sketch at :@ subscripting
Date: Sat, 03 Apr 2021 15:48:03 -0400 [thread overview]
Message-ID: <a18478fe-6118-42c4-948d-3bd99db2875d@www.fastmail.com> (raw)
In-Reply-To: <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@chazelas.org> 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
next prev parent reply other threads:[~2021-04-03 19:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 13:18 Mikael Magnusson
2020-12-19 9:13 ` Stephane Chazelas
2021-03-27 20:27 ` Bart Schaefer
2021-04-03 19:48 ` Lawrence Velázquez [this message]
2021-04-04 17:30 ` Daniel Shahaf
2021-04-10 20:38 ` Lawrence Velázquez
2021-04-10 21:59 ` Bart Schaefer
2021-04-13 11:54 ` Daniel Shahaf
2021-04-13 21:25 ` Bart Schaefer
2021-03-27 19:41 ` Lawrence Velázquez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a18478fe-6118-42c4-948d-3bd99db2875d@www.fastmail.com \
--to=vq@larryv.me \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).