zsh-workers
 help / color / mirror / code / Atom feed
* Baffling array substitution behavior
@ 2008-10-08  5:35 Bart Schaefer
  2008-10-09 13:38 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2008-10-08  5:35 UTC (permalink / raw)
  To: zsh-workers

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]
}

-- 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-10-09 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-08  5:35 Baffling array substitution behavior Bart Schaefer
2008-10-09 13:38 ` Peter Stephenson

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).