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

Re: Backward-compatible anonymous functions?



On Jun 7, 11:39am, Benjamin R. Haskell wrote:
}
} () {
}  	# this stuff happily parsed, but not executed
} }
} 
} 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?

I used to use "repeat 1 { ... }" for this kind of thing but of course
that doesn't have local options/variables.

The trouble is that to implement a scope you have to first define it and
then call it.  That requires a syntactic transformation that's probably
impossible in zsh because functions won't accept a block as an argument,
and aliases can only expand in place, they can't grab the command line
and append something at the end.

You might be able to write a scope push/pop module along the lines of
what I played with in workers/28271, but the popping part may still be
a problem.  I suppose if you created a builtin "toggle_scope" that
returns true when pushing a new local scope and false when popping to
the previous scope, then you could write

while toggle_scope; { ... }

and then the loop would execute once and the loop body would be in a
new scope.  Needs further thought to handle nested scopes, etc.



Messages sorted by: Reverse Date, Date, Thread, Author