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

Re: PATCH: anonymous functions (no documentation yet)



Oliver Kiddle wrote:
> Peter wrote:
> > Note this does not affect cases like
> > 
> >   $emptyvariable() { ... }
> 
> Out of interest, how does it affect:
>   ""() { ... }

That also turns into an empty argument list that is ignored.  I would
have to check why since my first guess was it would produce an invalid
empty function name.

> I partly ask because in the same way that
>   f g() { ... }
> defines two functions,
>   f ''() { ... }
> 
> might have the effect of defining a function f and running it
> immediately. And then you might write: f '' ''() { ... } and so on.

That ought to be a relatively straightforward addition, I think, subject
to the query above.

> What effect does all this have on the positional parameters?

Positional parameters from the surrounding area would be hidden and the
local parameter list empty.  I could easily copy them in so that they
could be used and modified without affecting the calling environment.

> Given that this feature will be seen as similar to plain { ... },
> people might find it confusing that redirections don't work. I know
> that you already know this but in other shells, redirections on function
> definitions are allowed and form part of the function.

Actually redirections work OK... the reason they don't work as they do
in other shells is because they do work on the definition, so it behaves
very much like { ... } in this respect.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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