zsh-workers
 help / color / mirror / code / Atom feed
From: Michal Politowski <mpol@charybda.icm.edu.pl>
To: zsh-workers@sunsite.dk
Cc: 92780@bugs.debian.org, Bart Schaefer <schaefer@candle.brasslantern.com>
Subject: Re: requests
Date: Thu, 19 Apr 2001 17:00:14 +0200	[thread overview]
Message-ID: <20010419170014.B1824@Amber.lab.icm.edu.pl> (raw)
In-Reply-To: <1010415032859.ZM27364@candle.brasslantern.com>; from Bart Schaefer <schaefer@candle.brasslantern.com> on Sun, 15 Apr 2001 03:28:58 +0000

On Sun, 15 Apr 2001 03:28:58 +0000, Bart Schaefer <schaefer@candle.brasslantern.com> wrote:
> On Apr 14,  8:24pm, Clint Adams wrote:
> } Subject: requests
> }
> } Michal, how do you want ${param[(r)$anotherparam]} to behave, if not
> } treating $anotherparam as a pattern?
> 
> He wants expansion to behave as it would outside subscript [ ]; that
> is, one must use $~param to get file globbing to happen, so he'd also
> like that rule to apply within subscripts.  It's fairly difficult, for
> example, to match a literal "*" using subscription.

Yes, that's exactly what I was expecting.

> } 1. in ${param[(r)$anotherparam]} the result of $anotherparam
> } is always treated as a pattern, it would be nice if one could use
> } $~anotherparam for this.
>
> The "reason" for this behavior is that the stuff inside the [ ] is,
> supposedly, parsed as if double-quoted.  So in order to treat as a
> pattern those strings that do NOT result from a parameter expansion,
> the (r) has to imply the same sort of tokenization as $~anotherparam.
>
> E.g. in $param[(r)foo*$bar], foo* has to first be parsed as if quoted
> (otherwise it'd be a file glob!) and then tokenized, so the same happens
> to $bar.
>
> Internally, the expansion of $anotherparam is done independently of
> the subscripting flag (r), which later tokenizes the fully-expanded
> subscript.
>
> One can get the desired effect by using ${param[(r)${(q)anotherparam}]},
> but (another inconsistency) this works for arrays but fails for string
> subscription on scalars.  That's clearly a bug.

So, do I understand correctly that changing (r) to behave as I'd like could be
rather difficult for the expected benefits (especially as there is the (q)
workaround (at least for arrays at the moment))?

Anyway I'm not desperately in need of this feature. I just noticed that
${param#foo*$bar} treating the $bar differently than ${param[(r)foo*$bar]}
is rather surprising for the casual user, independently of the lower level
reasons for this,
and I sent the report so that someday when zsh has all the possible features
someone could fix this as well.

> } 2. ${(B)param#pattern}
> } gives 1 when there's no match -- could give 0 or 1+$#param like
> } ${param[(i)pattern]}
> } the same for (E) and {...%...}
[...]
> Probably it could be changed because nobody is using it; in fact, I'm
> inclined to wonder what Michal is doing that caused him even to notice.

Actually it was nothing I personally was doing.
I was just looking for an answer to a usenet question, which was
exactly how to find if and where one variable's text is contained in another.
So for zsh (B) seemed like a simple and elegant solution, and it almost is.

-- 
Michal Politowski -- mpol@lab.icm.edu.pl
Warning: this is a memetically modified message


  parent reply	other threads:[~2001-04-19 15:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-15  0:24 requests Clint Adams
2001-04-16 16:06 ` (Fwd) requests Bart Schaefer
2001-04-16 17:29   ` requests Bart Schaefer
     [not found] ` <1010415032859.ZM27364@candle.brasslantern.com>
2001-04-19 15:00   ` Michal Politowski [this message]
2001-04-20  3:04     ` requests 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=20010419170014.B1824@Amber.lab.icm.edu.pl \
    --to=mpol@charybda.icm.edu.pl \
    --cc=92780@bugs.debian.org \
    --cc=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /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).