Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Baffling array substitution behavior
- X-seq: zsh-workers 25827
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Baffling array substitution behavior
- Date: Tue, 07 Oct 2008 22:35:53 -0700
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
You may have seen the the pids4kill function that I posted to zsh-users
a little while ago. When I was first trying it out, I mistook opt_args
for a plain array rather than an associative array, so I wrote:
local u=$opt_args[(I)-u]
Strangely, the entire assignment vanished on parameter substitution, so
what was executed was
local
which naturally was not what I wanted. Turns out this is a side-effect
of "setopt rcexpandparam", but is it really an intended side-effect?
Test program:
rcexbug() {
emulate -L zsh
setopt rcexpandparam
local -A hash
local -a full empty
full=(X x)
hash=(X x)
print ORDINARY ARRAYS
: The following behaves as documented in zshoptions
print FULL expand=$full
: The documentation does not discuss this next behavior
print EMPTY expand=$empty
print ASSOCIATIVE ARRAY
print Subscript flags returning many values
print FOUND key=$hash[(I)X] val=$hash[(R)x]
: This should behave like $empty, and does
print LOST key=$hash[(I)y] val=$hash[(R)Y]
print Subscript flags returning single values
: Doc says "substitutes ... empty string"
: but this behaves like an empty array
print CONFUSED key=$hash[(i)y] val=$hash[(r)Y]
}
--
Messages sorted by:
Reverse Date,
Date,
Thread,
Author