Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Backward-compatible anonymous functions?
- X-seq: zsh-users 16088
- From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Backward-compatible anonymous functions?
- Date: Tue, 7 Jun 2011 11:39:46 -0400 (EDT)
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
I have a system I don't administer where I'd like to use the same .zsh
files I use on all my other systems. It's running zsh-4.3.6, so it
doesn't have "anonymous functions" (I'll use "anonymous scopes"
hereafter).
For the (A) glob qualifier, introduced sometime in 4.3.9, I did this:
autoload -z is-at-least
if is-at-least 4.3.9 && (( ! $+in_solaris )) ; then
A () { reply=( $REPLY(:A) ) }
else
A () { reply=("$(perl -MCwd=realpath -we 'print realpath shift' $REPLY)") }
fi
Then, I can use (+A) everywhere instead of (A), and it works, at least
from from 4.3.2 up (That's the lowest Zsh version I use on a regular
basis -- not by choice), presumably with `perl`s greater than somewhere
in the 5.5 range.
When I figured out that the anonymous scope was what caused the problem
here:
() {
# this stuff happily parsed, but not executed
}
I found a nice, simple detection mechanism (better than relying on
is-at-least):
() { false } && has_anon=false || has_anon=true
But, I couldn't think of a similarly-simple transformation (akin to
"change (A) to (+A)") that I could apply where I used anonymous scopes.
Anyone here have a good one?
--
Best,
Ben
Messages sorted by:
Reverse Date,
Date,
Thread,
Author