From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: issues with ${array[x][y]}
Date: Tue, 6 Mar 2018 21:16:17 +0000 [thread overview]
Message-ID: <20180306211617.GA19175@chaz.gmail.com> (raw)
In-Reply-To: <180306090231.ZM28167@torch.brasslantern.com>
2018-03-06 09:02:31 -0800, Bart Schaefer:
> On Mar 6, 3:16pm, Stephane Chazelas wrote:
> } Subject: issues with ${array[x][y]}
> }
> } $ a=(foo bar)
> } $ x='a[1][1]'
> } $ echo ${(P)x}
> } foo
>
> This is happening because ${{(P)var}[1]} must treat ${(P)var} as an array
> any time the name referred to by $var is an array, so array-ness is being
> preserved when doing the first a[1] dereference.
Note:
$ zsh -c 'a=(foo bar); x=a[c=1][d=2]; echo ${(P)x}, $c, $d'
foo, 1,
The [d=2] part seems to be plainly ignored, it's not as if it
was treated as temp_a=($a[1]); echo ${a[2]} which I think is
what you're implying.
More generally, it seems that anything past what is parsed as a
valid variable name or variable with subscript is ignored:
$ zsh -c 'a=x; x=a+b; echo ${(P)x}'
x
>
> } There's also a consistency issue in that one can do:
> }
> } string[1]=x
> }
> } and reference ${array[1][1]}
> }
> } but:
> }
> } $ a[1][1]=b
> } zsh: no matches found: a[1][1]=b
>
> Having ${array[1][1]} is mostly for convenience, because it dates from
> before ${${array[1]}[1]} would have been syntactically valid. It was
> never intended to work as an assignment.
But would we not want that? Since we can do string[1]=x, it
seems natural that we would want to be able to do the same thing
for array elemments.
--
Stephane
next prev parent reply other threads:[~2018-03-06 21:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 15:16 Stephane Chazelas
2018-03-06 17:02 ` Bart Schaefer
2018-03-06 21:16 ` Stephane Chazelas [this message]
2018-03-08 19:11 ` Stephane Chazelas
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=20180306211617.GA19175@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=schaefer@brasslantern.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).