zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH] Support the mksh's ${|func;} substitution
Date: Thu, 12 Sep 2019 04:06:45 +0200	[thread overview]
Message-ID: <CAKc7PVBusxo0K-iJMXfiM+H2Lm1x+mkSf4ECnK9OajXVJqoLEA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7bOv3G6FBaMSRNSZhF_c4JNv7w7J6We-fSi+xSobzZpvA@mail.gmail.com>

On Thu, 12 Sep 2019 at 03:03, Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Wed, Sep 11, 2019 at 5:09 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > So you've implemented ${|code;} for mksh?
>
> Good grief, no.  I have never even (knowingly) USED mksh.  I just said
> that IF it had been me, I probably would have made a different syntax
> choice.

Ah, I've misread it then.

> > Ok, but this could use ...RLD; REPLY=HERE'. The use of reply is just
> > to simplify, i.e. to use different vars for the (x) embedded code and
> > for the substitution code?
>
> Again, by analogy to the glob qualifier -- the input ($REPLY) is a
> scalar, the output ($reply) is an array (which might or might not get
> string-ified by double-quoting).
>
> In an (e) glob, REPLY is set to each possible file name in turn, but
> $reply can provide multiple names to the final result.  I'm assuming
> you want ${(x...)array} to apply to each array element in turn, not to
> the entire array at once, so again REPLY is a scalar (each array
> element) but could be replaced by multiple elements in $reply.

That's interesting. The mapping could then look like:

array( "a" "b c" "d" )
func() { reply=( ${=REPLY} ); }
array=( ${(x^func^)array} )

and it would result in FOUR array elements, not three. This is a
concrete extension from the mapping via //(#m)*/${(x):-func}, which
cannot extend the array (nor contract it). I think that in order to
allow contraction of the result, the (x) flag could use only reply,
without REPLY as opposed to the (e), unless we do that reply being
just set invalidates REPLY and allows the empty result.

But also, the advanced (x) flag is quite complex. It might be a good
reason to lower the complexity by making the flag substitute only
reply contents.

> I think you grasped it, yes.
>
> Whether the syntax ${(x+func)...} would call "func" once for each
> array element (again by analogy to glob (e+func)) would be an
> implementation choice.  Too bad (x) for globs and (e) for parameters
> already have other meanings, so there's no way to make them use the
> identical key character.

Why only one + in the examples? (I've tried this syntax with (e), it
doesn't seem to support it).

I think that yes, it should call the func per each array element, to
allow the expanding / contracting featured mapping. Also, I wonder
what other interesting things can result from the 2-step code/data
providing to the substitution.

> > > > I think that the (x) flag should be at the top of the list, first.
> > >
> > > That can't be right.
> >
> > Ok, I've did hurry too much. The :- is point 7.
>
> This sounds more sensible.

Great. It seems that we're getting close to a final "draft".

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

  reply	other threads:[~2019-09-12  2:08 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06  0:52 Sebastian Gniazdowski
2019-09-06  0:54 ` Sebastian Gniazdowski
2019-09-06 23:16 ` Sebastian Gniazdowski
2019-09-07 12:16   ` Daniel Shahaf
2019-09-07 15:07 ` Stephane Chazelas
2019-09-07 18:09   ` Sebastian Gniazdowski
2019-09-07 20:19     ` Stephane Chazelas
2019-09-07 21:19       ` Sebastian Gniazdowski
2019-09-10  2:20         ` Sebastian Gniazdowski
2019-09-10  5:29           ` Bart Schaefer
2019-09-10 18:21             ` Sebastian Gniazdowski
2019-09-10 19:38               ` Bart Schaefer
2019-09-12  0:08                 ` Sebastian Gniazdowski
2019-09-12  1:03                   ` Bart Schaefer
2019-09-12  2:06                     ` Sebastian Gniazdowski [this message]
2019-09-12  5:35                       ` Bart Schaefer
2019-09-12  6:00                         ` Sebastian Gniazdowski
2019-09-12  6:55                           ` Bart Schaefer
2019-09-13 20:28                             ` Sebastian Gniazdowski
2019-09-13 21:33                               ` Bart Schaefer
2019-09-13 21:36                                 ` Bart Schaefer
2019-09-14  0:41                                   ` Sebastian Gniazdowski
2019-09-14  0:44                                     ` Sebastian Gniazdowski
2023-05-03 14:46 Sebastian Gniazdowski
2023-07-04  1:55 ` Bart Schaefer
2023-07-04 18:53   ` Lawrence Velázquez
2023-07-05  5:32     ` Bart Schaefer
2023-07-05  6:30       ` Bart Schaefer
2023-07-06  1:39       ` Bart Schaefer
2023-07-06  2:27         ` Mikael Magnusson
2023-07-06  4:00           ` Bart Schaefer
2023-07-18  3:14             ` Bart Schaefer

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=CAKc7PVBusxo0K-iJMXfiM+H2Lm1x+mkSf4ECnK9OajXVJqoLEA@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@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).