zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: RFC PATCH: Sketch at :@ subscripting
Date: Sat, 19 Dec 2020 09:13:14 +0000	[thread overview]
Message-ID: <20201219091314.dxslsscyiqffa3il@chazelas.org> (raw)
In-Reply-To: <20201218131815.25999-1-mikachu@gmail.com>

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];

And in assignments as well:

@list[@idx] = qw(new values here);

would be more useful.

It's unfortunate that "," is used for ranges in $a[1,3] in zsh
especially considering that "," is also an arithmetic operator
(btw:
  $ a=({a..z})
  $ echo ${a[1,3]}
  a b c
  $ i=1,3
  $ echo ${a[i]}
  c
  $ echo ${a[$i]}
  a
??) and that {1,3,{5..7}} otherwise follows the perl semantics
(and extends it as it allows backward ranges).

${list[2 6 8]} in zsh wouldn't work as ${list[2 -1]} already
means something different, but maybe ${list[2;6,9;${(j[;])idx},-1]}
would?

That would mean no backward range as $a[3,1] ATM is the empty
list but backward sets would still be possible with $a[3;2;1].

Maybe another option could be $a[{1,4,{8..2},$^idx}] so as to
reuse an already known syntax?

Except that:

$ i=(a b)
$ echo {1,2,$^i}.
1. 2. a. 1. 2. b.
$ echo {1,2,{a,b}}.
1. 2. a. b.

Syntax would also have to be restricted to a[{...}], no
a[{1,2}0] for instance.

a[{${(f)^"$(shuf -n 5 -i 1-100)"}]=({a..e})
soon becomes awkward as well.

There's also the question of

a[1;5]=(a b c)
a[1;5]=(a)
...

Having a syntax that could also apply to associative arrays
would be best.

-- 
Stephane


  reply	other threads:[~2020-12-19  9:13 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 [this message]
2021-03-27 20:27   ` Bart Schaefer
2021-04-03 19:48     ` Lawrence Velázquez
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=20201219091314.dxslsscyiqffa3il@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=mikachu@gmail.com \
    --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).