Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: BUG: zsh-3.1.5-pws-14: parameter expansion not working properly



On Apr 12,  9:17am, Sven Wischnowsky wrote:
} Subject: Re: BUG: zsh-3.1.5-pws-14: parameter expansion not working proper
}
} The rule of thumb is now that one should use the `(@)' flag whenever
} the thing is in double quotes and one wants to work on arrays.

When I first saw the patch that introduced that change, I thought that
introducing the extra consistency sounded like a good thing.

	bar=(xa)
	print -l "${${(@)bar}[1]}" "${(@)${bar}[1]}"

Zsh 3.0.5 prints

	x
	x

But 3.1.5-pws-14 prints

	x
	xa

which is nice, because you can tell a singleton array from a scalar.

Now that I've seen/used it in practice a few times, I'm not so sure any
more.  The more radical change, and one which bothers me a lot, is the
effect when the array has more than one element:

	foo=(xa yb zc)
	print -l "${${(@)foo}[1]}" "${(@)${foo}[1]}"

Zsh 3.0.5 prints

	xa
	x

But 3.1.5-pws-14 prints

	x
	xa

That's completely reversed the semantics, and thus is a serious problem.

Another difficulty is that (@) has to be repeated at *every* level of a
nested expansion, from the innermost ${...} at which an array is desired
all the way to the outermost braces.

	"${${${${(@)foo}}}}"		== "$foo[@]"

To get the equivalent effect now, having to write

	"${(@)${(@)${(@)${(@)foo}}}}"	== "$foo[@]"

is error-prone and just plain annoying.  There must be a better way.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author