From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: More about ${(A)param=} and some stuff about subst.c
Date: Wed, 23 Jun 1999 05:09:25 +0000 [thread overview]
Message-ID: <990623050925.ZM31030@candle.brasslantern.com> (raw)
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
reply other threads:[~1999-06-23 5:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=990623050925.ZM31030@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=zsh-workers@sunsite.auc.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).