zsh-workers
 help / color / mirror / code / Atom feed
* More about ${(A)param=} and some stuff about subst.c
@ 1999-06-23  5:09 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 1999-06-23  5:09 UTC (permalink / raw)
  To: zsh-workers

I've been staring at this some more ... consider:

zsh% : ${(A)=arr1=foo bar}
zsh% echo $#arr1
2
zsh% : ${(A)=arr2="foo bar"}
zsh% echo $#arr2
2

Now, why is it that the quotes in the arr2 case didn't make any difference
at all?  Is it really right that they shouldn't?  And:

zsh% : ${(A)arr3=foo "bar baz"}
zsh% echo $#arr3 $arr3
1 foo bar baz

It's true that this is the same behavior as far back as at least 3.0.0 (I
no longer have any older binaries around) but it seems a bit strange when
I think about it.  Either the quotes should mean something, or they should
not get stripped out.

So I went tracing through the way that the code gets here.  The relevant
bit starts at about line 1308 of subst.c; it first calls multsub(), then
if either shwordsplit or the (s) flag was present it calls sepsplit().  So
the only way to assign a "real" array in this construct is to be sure that
shwordsplit is off and place an expansion on the RHS of the `=' that will
yield an array out of multsub().

That led me into multsub(), which has had a bit of pounding recently; but
this one thing has been unchanged since 3.0.0:  as far as I can tell, the
`sep' parameter of multsub() isn't used at all.  It would appear from the
comment above the function that it is supposed to be passed on to sepjoin()
when `if (a && mult_isarr)' is false, but that's not done -- which may be
just as well because in the one case when something non-NULL is given to
multsub() in that parameter, I'm not sure that it's the right thing.

Another question is whether glob_assign should apply:

zsh% setopt globassign
zsh% : ${(A)arr4=*}
zsh% echo $arr4
*
zsh% : ${(A)~arr5=*}
zsh% echo $arr5
*

Which brings me finally to ${(A)param=}, the original problem.  As long as
quotes don't matter in the RHS for other purposes, I don't like the idea
of special-casing that instance to create an empty array.  So it *could*
be fixed to treat any empty string returned from multsub() as creating an
empty array; thus ${(A)param=''} would also create an empty array.  Other
solutions might be possible, but not without cleaning up the rest of these
issues too.

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-06-23  5:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-23  5:09 More about ${(A)param=} and some stuff about subst.c Bart Schaefer

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