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

Re: PATCH: anonymous functions (no documentation yet)



On Thu, Jun 26, 2008 at 04:06:36PM +0100, Peter Stephenson wrote:
> 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.

Well,

""() echo test
''

Does echo "test".

I was finding it consistent of zsh that it would allow anything
as a function name, as there's no reason it shouldn't allow
anything that can be an argument to a simple command.

'{'() { echo test; }


Also note some funny alternatives:

$ bash -c 'a=c; a=a command eval "echo \$a; a=b; echo \$a"; echo $a'
a
b
c
$ ksh -c 'a=c; a=a command eval "echo \$a; a=b; echo \$a"; echo $a'
a
b
c
$ zsh -c 'a=c; a=a command eval "echo \$a; a=b; echo \$a"; echo $a'
zsh:1: command not found: eval
c
$ ARGV0=sh zsh -c 'a=c; a=a command eval "echo \$a; a=b; echo \$a"; echo $a'
a
b
c

$ bash -c 'a=c; a=a command . /dev/stdin << \EOF
echo $a; a=b; echo $a
EOF
echo $a'
a
b
c
$ ksh -c 'a=c; a=a command . /dev/stdin << \EOF
echo $a; a=b; echo $a
EOF
echo $a'
a
b
c
$ zsh -c 'a=c; a=a command . /dev/stdin << \EOF
echo $a; a=b; echo $a
EOF
echo $a'
zsh:1: permission denied: .
c
$ ARGV0=sh zsh -c 'a=c; a=a command . /dev/stdin << \EOF
echo $a; a=b; echo $a
EOF
echo $a'
a
b
c

Cheers,
Stéphane



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