From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: Belaboring substitution syntax
Date: Thu, 17 Nov 2022 08:02:10 -0800 [thread overview]
Message-ID: <33451f56-953e-a4a5-ddb1-3fb74fa505bc@eastlink.ca> (raw)
In-Reply-To: <CAN=4vMovAvSK8QOJ-uMiK6ujdP+vvBF+d3SUHyX-oLNQaA30cg@mail.gmail.com>
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. :-)
next prev parent reply other threads:[~2022-11-17 16:03 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 0:43 coloring substitution seems to eat next line Ray Andrews
2022-11-10 8:02 ` Roman Perepelitsa
2022-11-10 18:25 ` Ray Andrews
2022-11-10 18:36 ` Roman Perepelitsa
2022-11-10 18:45 ` Ray Andrews
2022-11-10 18:54 ` Bart Schaefer
2022-11-10 19:28 ` Ray Andrews
2022-11-10 20:22 ` Bart Schaefer
2022-11-10 21:42 ` Ray Andrews
2022-11-10 21:51 ` Roman Perepelitsa
2022-11-11 17:24 ` Ray Andrews
2022-11-10 22:47 ` Bart Schaefer
2022-11-10 23:07 ` Ray Andrews
2022-11-10 23:27 ` Bart Schaefer
2022-11-11 15:00 ` Ray Andrews
2022-11-11 18:15 ` Bart Schaefer
2022-11-11 18:50 ` Ray Andrews
2022-11-11 19:25 ` Bart Schaefer
2022-11-11 21:26 ` Ray Andrews
2022-11-12 4:24 ` Bart Schaefer
2022-11-12 14:03 ` Ray Andrews
2022-11-13 15:09 ` Ray Andrews
2022-11-14 14:12 ` Roman Perepelitsa
2022-11-14 17:08 ` Ray Andrews
2022-11-14 17:12 ` Roman Perepelitsa
2022-11-14 18:58 ` Ray Andrews
2022-11-14 20:00 ` Bart Schaefer
2022-11-14 23:25 ` Ray Andrews
2022-11-15 14:17 ` Belaboring substitution syntax Ray Andrews
2022-11-16 1:49 ` Bart Schaefer
2022-11-16 2:54 ` Ray Andrews
2022-11-16 6:26 ` Bart Schaefer
2022-11-16 14:08 ` Ray Andrews
2022-11-16 14:13 ` Roman Perepelitsa
2022-11-17 2:31 ` Bart Schaefer
2022-11-17 8:59 ` Roman Perepelitsa
2022-11-17 16:02 ` Ray Andrews [this message]
2022-11-16 20:46 ` Ray Andrews
2022-11-16 10:32 ` Roman Perepelitsa
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=33451f56-953e-a4a5-ddb1-3fb74fa505bc@eastlink.ca \
--to=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/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).