Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Belaboring substitution syntax
On 2022-11-17 00:59, Roman Perepelitsa wrote:
...
And these four are equivalent:
${array[@]}
${(@)array}
${array}
$array
Roman.
Thanks, that's what I call quality explanation, I'm going to save that
whole post to my cheat sheet and work it over at length. 2/3 of my own
difficulties here involve all this splitting/joining stuff. Mostly
because I use Sebastian's n_list() quite a bit and it demands
lines/elements for input, with blank lines and spaces in filenames
protected. The construction that seems robust is like this:
n_list "${array[@]}"
... for the reasons you mention. A useful document would be the
Unabridged Guide to Zsh Arrays (their splitting, splicing, slicing and
dicing, with protections and without, with all flags explained and
specimens of every possible syntax and when you'd want to use them).
I know it's far too late in the game to even think about fundamental
changes, but if we had to do it all over again I'd advocate for a single
universal expansion grammar:
${(CONTROL) FIELD / FIELD / FIELD }
No '//' '##' '%%' or any of that. '/' is the universal separator, and
what is done to the fields is entirely explained within the
parenthesis. No more worries about special characters except '/' and
maybe " " and ' ' and backslash cuz those expansion controls are
robust. Within the parenthesis there are zero worries about literals,
it's 100% operators so the syntax-space is unlimited. Within the fields
there are zero operators (except quote expansions) so parsing becomes
vastly simpler.
${(S:a!$%&@N/(xx^)**/*<>) ${array} / ${filter} }
... what's in the () explains exactly what is to be done vis a vis the
two fields ... or more.
${(VERBS) NOUNS / NOUNS / NOUNS }
${(PREDICATES) SUBJECTS } ... that's the way a grammar should look.
Basically 'flags' do everything and verbs and nouns are never
intermingled. That's the reason glob qualifiers are so stinking
powerful, cuz within the parenthesis their is nothing one might not
achieve.
Nevermind. :-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author