Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: priority problem of ":|" and ":*"
- X-seq: zsh-users 17497
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: priority problem of ":|" and ":*"
- Date: Wed, 26 Dec 2012 01:10:19 -0800
- In-reply-to: <20121225231133.GA8145@localhost.localdomain>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20121224105241.GA24051@localhost.localdomain> <20121225231133.GA8145@localhost.localdomain>
On Dec 26, 7:11am, Han Pingtian wrote:
}
} > % a1=(a b c);a2=('a b c');print "${#a1:|a2}"
} > 3
} >
} > in this, the priority should be "5 Double-quoted joining" first, then "7
} > modifiers", then "9 length". So 'print "${#a1:|a2}"' should output 0 I
} > think. And the ":*" has the same problem.
Hmm.
% a1=(a b c); print "${#a1}" :"${a1}":
3 :a b c:
Plainly if length were applied after double-quoted joining, the above
should print 5 rather than 3. As I'm pretty sure this hasn't changed
*ever*, it must be that the documentation is wrong, not that :| has the
wrong priority.
And in fact poring through the code it appears that rule 5 double-quoted
joining is explicitly SKIPPED when the length is requested:
if (isarr) {
if (nojoin)
isarr = -1;
if (qt && !getlen && isarr > 0) {
val = sepjoin(aval, sep, 1);
isarr = 0;
}
}
"qt" there means double-quoted, but "getlen" means the "#" was seen. So
when evaluating length, we do not remove arrayness.
} For the ":*", we have this result:
}
} % a1=(a b c);a2=(a b c);print "${#a1:*a2}"
} 3
This is consistent with the above.
I admit that this is not intuitive when applying operations to the members
of the array, but it's the way #, ##, %, %%, and :# have always worked, so
it's a bit late to change it and arguably worse to make it different for
:| and :*. (My sympathies if anyone's mail reader is too clever by half
and renders a lot of that as emoticons.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author