Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Backward-compatible anonymous functions?



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