Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: issues with ${array[x][y]}
- X-seq: zsh-workers 42428
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: issues with ${array[x][y]}
- Date: Tue, 6 Mar 2018 21:16:17 +0000
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=y2u2OSpSpCijRszoQnKIxmIcGVNbpZA7X0W50MUxRbM=; b=f55BCGKPcgPCtdZRn0G3pruUQSa6KjXVkvtXPcRiPRjuUUps88v4Tm2LlK1odQBiEk d1j2LSTCJXtEl/J5lsCob0G+bEzE0/dGtl20eXl6iYLyRkemTf7GIb0gbs3LDlmtmmAi pIg/7xvzxSIyLX2YNwBoEWs1gIdxFpr/BUzbkjUJ5wplI06DAVcNDjAKRIcnOfC+pNpJ lQd/2q6cK+WK7Y/lAYkBHkI27uyM3gs2HphWzmJGrT+xovtkJIZpWnYHj7KgNeLjyh8z 12onxukC1mAA8C0nDlRZ4+3YYdD9EYAW7CFeVvQL1hUqsez2dgjqwkwSK7LWab0onfyQ +RoQ==
- In-reply-to: <180306090231.ZM28167@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20180306151644.GA10296@chaz.gmail.com> <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author