From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Baffling array substitution behavior
Date: Tue, 07 Oct 2008 22:35:53 -0700 [thread overview]
Message-ID: <081007223555.ZM18217@torch.brasslantern.com> (raw)
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]
}
--
next reply other threads:[~2008-10-08 5:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-08 5:35 Bart Schaefer [this message]
2008-10-09 13:38 ` Peter Stephenson
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=081007223555.ZM18217@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@sunsite.dk \
/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).