#526924 zparseopts: should use lists as values in assoc array

Package:
zsh
Source:
zsh
Description:
shell with lots of features
Submitter:
martin f krafft
Date:
2013-11-08 01:51:04 UTC
Severity:
wishlist
#526924#5
Date:
2009-05-04 13:01:24 UTC
From:
To:
piper:~|master|% set -- -a1 -a2; zparseopts -A arr a+:; echo $arr[-a]
12

Unfortunately, this greatly reduces the usefulness of the builtin,
since it's impossible to tell from the hash value whether the
options where -a1 -a2 or -a12.

It would be better if the value pointed to by the hash would contain
a list, such that $arr[-a] in the above would be (1 2).

#526924#10
Date:
2009-05-05 16:05:28 UTC
From:
To:
Unfortunately we don't handle arrays as values of associate arrays
(yet?) but you can do something like

set -- -a1 -a2; zparseopts 'a+:=arr'; print -l $arr

although this seems to set arr=(1 -a 2), which is not what I
expected to happen.

#526924#15
Date:
2009-05-05 16:36:35 UTC
From:
To:
also sprach Clint Adams <schizo@debian.org> [2009.05.05.1805 +0200]:

Aha.

pulse:~|master|% declare -A foo; foo[Clint]=(1 2 3)
zsh: foo: attempt to set slice of associative array

:(

Yeah, that's a bit weird, isn't it? Should I clone the bug?

As for the original bug, maybe just insering $IFS[0] between
elements would do?

#526924#20
Date:
2009-05-05 17:05:06 UTC
From:
To:
On May 5,  4:05pm, Clint Adams wrote:
}
} set -- -a1 -a2; zparseopts 'a+:=arr'; print -l $arr
}
} although this seems to set arr=(1 -a 2), which is not what I
} expected to happen.

The parameter is set to (-a 1 -a 2), but "print -l $arr" is consuming
the first -a as an option to print.

#526924#25
Date:
2009-05-05 17:28:33 UTC
From:
To:
retitle 526924 zparseopts: separate options in

also sprach Bart Schaefer <schaefer@brasslantern.com> [2009.05.05.1905 +0200]:

Confirmed. This leaves the question of whether something could be
used to separated the values in the case of

  set -- -a1 -a2; zparseopts -A arr a+:-; print -- $arr[-a]