zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: issues with ${array[x][y]}
Date: Thu, 8 Mar 2018 19:11:28 +0000	[thread overview]
Message-ID: <20180308191128.GA24398@chaz.gmail.com> (raw)
In-Reply-To: <20180306151644.GA10296@chaz.gmail.com>

2018-03-06 15:16:44 +0000, Stephane Chazelas:
[...]
> string[1]=x
> 
> and reference ${array[1][1]}
> 
> but:
> 
> $ a[1][1]=b
> zsh: no matches found: a[1][1]=b
> $ ((a[1][1] = 2))
> zsh: bad base syntax
> $ typeset 'a[1][1]=2'
> zsh: not an identifier: a[1][1]
[...]

Also:

$ a=(213 345)
$ echo $((a[1])) $((${a[1]}))
213 213
$ echo $((a[1][2]))
zsh: bad base syntax
$ echo $((${a[1][2]}))
1

For reference, in ksh93, ${a[1][2][3]} is used for its
multi-dimensional arrays, and

${a[1][2]}
$((a[1][2]))
a[1][2]=x
((a[1][2] = 3))
typeset -n b='a[1][2]'

are recognised consistently, but ${a[1][2]=x} is buggy:

$ ksh -c ': ${a[1][2]=x}; typeset -p a'
typeset -a a=([1]=([0]=) )
$ ksh -c 'a[1][2]=x; typeset -p a'
typeset -a a=([1]=([2]=x) )

(of course, it's more important for ksh93, as multi-dimensional
arrays would be less useful without, while zsh's a[1][2] setting
the second character of the first element of a is not going to
be often useful (except maybe for the $mapfile case mentioned
earlier))

-- 
Stephane


      parent reply	other threads:[~2018-03-08 19:11 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
2018-03-08 19:11 ` Stephane Chazelas [this message]

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=20180308191128.GA24398@chaz.gmail.com \
    --to=stephane.chazelas@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).