zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: (Fwd) Re: requests
Date: Mon, 16 Apr 2001 16:06:04 +0000	[thread overview]
Message-ID: <1010416160604.ZM12205@candle.brasslantern.com> (raw)
In-Reply-To: <20010414202410.A10021@dman.com>

My apologies if this ends up appearing twice -- I sent it Saturday night
but it still hasn't come through the archives.

In the interim since the text below was written, I've posted a patch that
includes a fix for the #3 bug.

--- Forwarded mail from <schaefer@candle.brasslantern.com> ("Bart Schaefer")

From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
Date: Sun, 15 Apr 2001 03:28:58 +0000
To: zsh-workers@sunsite.dk
Subject: Re: requests
Cc: 92780-forwarded@bugs.debian.org, mpol@charybda.icm.edu.pl

The timing of this is interesting, as I've just spent the entire day
fooling with SourceForge bug #104052 (without making much headway).

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.

} 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.

} 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 {...%...}

This is a known inconsistency (there's even a comment about it in the
Tests/*parameter.ztst file).  It's been left unchanged for backwards
compatibility, though it's not clear whether its use is widespread
enough that it would cause an outcry were it changed.

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.
 
} 3. ${param[(i)pattern]} behaves differently for scalars and for arrays
} when there is no match. For scalars returns 0, for arrays the index of
} last element + 1. 

I think that one's just an implementation oversight; both forward and
reverse subscripting of scalars fall through to the same return value
when the pattern isn't found.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


---End of forwarded mail from <schaefer@candle.brasslantern.com> ("Bart Schaefer")

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


  reply	other threads:[~2001-04-16 16:07 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 ` Bart Schaefer [this message]
2001-04-16 17:29   ` requests Bart Schaefer
     [not found] ` <1010415032859.ZM27364@candle.brasslantern.com>
2001-04-19 15:00   ` requests Michal Politowski
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=1010416160604.ZM12205@candle.brasslantern.com \
    --to=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).