zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Word splitting/joining inside [[ ]]
Date: Sun, 13 Dec 2015 18:28:10 +0000	[thread overview]
Message-ID: <20151213182810.158a935e@ntlworld.com> (raw)
In-Reply-To: <151211203147.ZM4122@torch.brasslantern.com>

On Fri, 11 Dec 2015 20:31:47 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> [[ $words = ${(on)=words} ]]
> 
> Doesn't work.  It's always true.  Confused, I setopt xtrace and discover:
>>>
> By accident I discovered that adding a supposedly-meaningless extra level
> of nested expansion makes it work:
> 
> torch% [[ $words = ${${(on)=words}} ]]
> +zsh:12> [[ 'I have a string of words' == a\ have\ I\ of\ string\ words ]]
> 
> What's going on here?

I guess this is something to do with the effect of singsub() and the
PREFORK_SINGLE flag which propagates into paramsubst() but not further
into multsub() which handles nested expansion.  There are likely to be
lots of combinations of effects like this that have never been thought
through.

In particular, forcing single substitution at the top level inhibits
various things happening (sometimes even if you've explicitly indicated
an affect that would later undo them) whereas the combination of multsub
and a paramsubst on top of it is smarter about trying to work out the
end effect.  So in your second case multsub produces array behaviour which
the top level paramsubst can then rationalise back down to a single
expression, while in your first case there's no leeway for array
behaviour at any point.

I don't have any ideas about easy ways to improve singsub.  It looks
a potential minefield.

pws


      reply	other threads:[~2015-12-13 18:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-12  4:31 Bart Schaefer
2015-12-13 18:28 ` Peter Stephenson [this message]

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=20151213182810.158a935e@ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).