Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
More about ${(A)param=} and some stuff about subst.c
- X-seq: zsh-workers 6792
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: More about ${(A)param=} and some stuff about subst.c
- Date: Wed, 23 Jun 1999 05:09:25 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author