zsh-workers
 help / color / mirror / code / Atom feed
* Re: Bug#537596: regression: parse error near `()' in function definition
       [not found] <20090719171651.GA7217@piper.oerlikon.madduck.net>
@ 2009-07-19 23:20 ` Clint Adams
  2009-07-20  4:18   ` Bart Schaefer
  2009-07-20  8:27   ` Peter Stephenson
  0 siblings, 2 replies; 8+ messages in thread
From: Clint Adams @ 2009-07-19 23:20 UTC (permalink / raw)
  To: zsh-workers; +Cc: martin f krafft, 537596

Does this have anything to do with users/14240?

On Sun, Jul 19, 2009 at 07:16:51PM +0200, martin f krafft wrote:
> A regression introduced by this build:
> 
> This works (I use eval since those functions are defined in a loop[0])
> 
> % eval 'de() { (_de-en $*; _en-de $*) | more }'
> % which de
> de () {
>   (
>     _de-en $*
>     _en-de $*
>   ) | more
> }
> 
> But:
> 
> % eval 'lt() { (_lt-en $*; _en-lt $*) | more }'
> zsh: parse error near `()'
> 
> Alright, so lt is special:
> 
> % which lt
> lt: aliased to ls -lt
> 
> But that does not prevent de from being defined:
> 
> % alias de=foo
> % eval 'de() { (_de-en $*; _en-de $*) | more }'
> % which de
> de: aliased to foo
> 
> [0] http://git.madduck.net/v/etc/zsh.git?a=blob;f=.zsh/zshrc/30_aliases;h=f206c8c8bfeaf777a6f4ebef5ea4b54746376b7e;hb=HEAD#l131


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function definition
  2009-07-19 23:20 ` Bug#537596: regression: parse error near `()' in function definition Clint Adams
@ 2009-07-20  4:18   ` Bart Schaefer
  2009-07-20  8:27   ` Peter Stephenson
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2009-07-20  4:18 UTC (permalink / raw)
  To: zsh-workers

On Jul 19, 11:20pm, Clint Adams wrote:
}
} Does this have anything to do with users/14240?

It's possible, but I can't reproduce the error.  Does he possibly also
have "ls" aliased to something so that there's more than one expansion
going on?

Note that in neither of his examples is he actually doing what he
wants to do.  In the first case (if it "worked") he'd be creating
two functions named "ls" and "-lt", and in the second example he's
creating a function named "foo" (not one named "de").
 
} On Sun, Jul 19, 2009 at 07:16:51PM +0200, martin f krafft wrote:
} > A regression introduced by this build:
} > 
} > This works (I use eval since those functions are defined in a loop[0])
} > 
} > % eval 'de() { (_de-en $*; _en-de $*) | more }'
} > % which de
} > de () {
} >   (
} >     _de-en $*
} >     _en-de $*
} >   ) | more
} > }
} > 
} > But:
} > 
} > % eval 'lt() { (_lt-en $*; _en-lt $*) | more }'
} > zsh: parse error near `()'
} > 
} > Alright, so lt is special:
} > 
} > % which lt
} > lt: aliased to ls -lt
} > 
} > But that does not prevent de from being defined:
} > 
} > % alias de=foo
} > % eval 'de() { (_de-en $*; _en-de $*) | more }'
} > % which de
} > de: aliased to foo
} > 
} > [0] http://git.madduck.net/v/etc/zsh.git?a=blob;f=.zsh/zshrc/30_aliases;h=f206c8c8bfeaf777a6f4ebef5ea4b54746376b7e;hb=HEAD#l131
}-- End of excerpt from Clint Adams



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function definition
  2009-07-19 23:20 ` Bug#537596: regression: parse error near `()' in function definition Clint Adams
  2009-07-20  4:18   ` Bart Schaefer
@ 2009-07-20  8:27   ` Peter Stephenson
  2009-07-20  8:37     ` Mikael Magnusson
  2009-07-20  8:46     ` martin f krafft
  1 sibling, 2 replies; 8+ messages in thread
From: Peter Stephenson @ 2009-07-20  8:27 UTC (permalink / raw)
  To: zsh-workers; +Cc: martin f krafft, 537596

On Sun, 19 Jul 2009 23:20:41 +0000
Clint Adams <schizo@debian.org> wrote:
> On Sun, Jul 19, 2009 at 07:16:51PM +0200, martin f krafft wrote:
> > % eval 'lt() { (_lt-en $*; _en-lt $*) | more }'
> > zsh: parse error near `()'
> > 
> > Alright, so lt is special:
> > 
> > % which lt
> > lt: aliased to ls -lt

Assuming lt was defined as an alias first, this has always been the wrong
thing to do:

% alias lt="one two"
% eval 'lt() { (_lt-en $*; _en-lt $*) | more }'
% which one two
one () {
        (
                _lt-en $*
                _en-lt $*
        ) | more
}
two () {
        (
                _lt-en $*
                _en-lt $*
        ) | more
}

This is not a new feature; it's been mentioned in the FAQ for many years.


2.3: Why do my csh aliases not work?  (Plus other alias pitfalls.)

...

  There is one other serious problem with aliases: consider

    alias l='/bin/ls -F'
    l() { /bin/ls -la "$@" | more }

  `l' in the function definition is in command position and is expanded
  as an alias, defining `/bin/ls' and `-F' as functions which call
  `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  `function' to define a function, which doesn't expand aliases.  It is
  possible to argue for extra warnings somewhere in this mess.

  Bart Schaefer's rule is:  Define first those aliases you expect to
  use in the body of a function, but define the function first if the
  alias has the same name as the function.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function  definition
  2009-07-20  8:27   ` Peter Stephenson
@ 2009-07-20  8:37     ` Mikael Magnusson
  2009-07-20  8:50       ` Peter Stephenson
  2009-07-20  8:46     ` martin f krafft
  1 sibling, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2009-07-20  8:37 UTC (permalink / raw)
  To: zsh-workers; +Cc: martin f krafft, 537596

2009/7/20 Peter Stephenson <pws@csr.com>:
> On Sun, 19 Jul 2009 23:20:41 +0000
> Clint Adams <schizo@debian.org> wrote:
>> On Sun, Jul 19, 2009 at 07:16:51PM +0200, martin f krafft wrote:
>> > % eval 'lt() { (_lt-en $*; _en-lt $*) | more }'
>> > zsh: parse error near `()'
>> >
>> > Alright, so lt is special:
>> >
>> > % which lt
>> > lt: aliased to ls -lt
>
> Assuming lt was defined as an alias first, this has always been the wrong
> thing to do:
>
> % alias lt="one two"
> % eval 'lt() { (_lt-en $*; _en-lt $*) | more }'
> % which one two
> one () {
>        (
>                _lt-en $*
>                _en-lt $*
>        ) | more
> }
> two () {
>        (
>                _lt-en $*
>                _en-lt $*
>        ) | more
> }
>
> This is not a new feature; it's been mentioned in the FAQ for many years.

Just thought I'd mention you can also use \ at any time to escape an alias:

% alias lt="one two"
% eval '\lt() { echo foo }'
% which lt
lt: aliased to one two
% unalias lt
% which lt
lt () {
	echo foo
}
% alias lt="one two"
% which lt
lt: aliased to one two
% lt
zsh: command not found: one
% \lt
foo
% l\t
foo

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function definition
  2009-07-20  8:27   ` Peter Stephenson
  2009-07-20  8:37     ` Mikael Magnusson
@ 2009-07-20  8:46     ` martin f krafft
  1 sibling, 0 replies; 8+ messages in thread
From: martin f krafft @ 2009-07-20  8:46 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers, 537596

[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]

also sprach Peter Stephenson <pws@csr.com> [2009.07.20.1027 +0200]:
>   `l' in the function definition is in command position and is expanded
>   as an alias, defining `/bin/ls' and `-F' as functions which call
>   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
>   `function' to define a function, which doesn't expand aliases.  It is
>   possible to argue for extra warnings somewhere in this mess.

Indeed, this fixed my problem, and I also renamed the function to
something else, now that I found out about the nameclash. Warnings
would be nice.

However, there still seems to be some regression, but I cannot quite
reproduce this for other cases. E.g. it is still possible to define
a function -F without the error.

-- 
 .''`.   martin f. krafft <madduck@d.o>      Related projects:
: :'  :  proud Debian developer               http://debiansystem.info
`. `'`   http://people.debian.org/~madduck    http://vcs-pkg.org
  `-  Debian - when you have better things to do than fixing systems
 
there are only 10 types of people in the world:
those who understand binary and those who don't.

[-- Attachment #2: Digital signature (see http://martin-krafft.net/gpg/) --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function definition
  2009-07-20  8:37     ` Mikael Magnusson
@ 2009-07-20  8:50       ` Peter Stephenson
  2009-07-20  9:10         ` Mikael Magnusson
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2009-07-20  8:50 UTC (permalink / raw)
  To: zsh-workers

Mikael Magnusson wrote:
> Just thought I'd mention you can also use \ at any time to escape an alias:

Something like that is worth mentioning.

Index: Etc/FAQ.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Etc/FAQ.yo,v
retrieving revision 1.47
diff -u -r1.47 FAQ.yo
--- Etc/FAQ.yo	21 Apr 2009 09:33:37 -0000	1.47
+++ Etc/FAQ.yo	20 Jul 2009 08:50:23 -0000
@@ -819,6 +819,14 @@
   use in the body of a function, but define the function first if the
   alias has the same name as the function.
 
+  If you aware of the problem, you can always escape part or all of the
+  name of the function:
+  verb(
+     'l'() { /bin/ls -la "$@" | more }
+  )
+  Adding the quotes has no effect on the function definition, but
+  suppresses alias expansion for the function name.  Hence this is
+  guaranteed to be safe.
 
 sect(Similarities with tcsh)
 

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function  definition
  2009-07-20  8:50       ` Peter Stephenson
@ 2009-07-20  9:10         ` Mikael Magnusson
  2009-07-20  9:15           ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2009-07-20  9:10 UTC (permalink / raw)
  To: zsh-workers

2009/7/20 Peter Stephenson <pws@csr.com>:
> Mikael Magnusson wrote:
>> Just thought I'd mention you can also use \ at any time to escape an alias:
>
> Something like that is worth mentioning.
>
> Index: Etc/FAQ.yo
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Etc/FAQ.yo,v
> retrieving revision 1.47
> diff -u -r1.47 FAQ.yo
> --- Etc/FAQ.yo  21 Apr 2009 09:33:37 -0000      1.47
> +++ Etc/FAQ.yo  20 Jul 2009 08:50:23 -0000
> @@ -819,6 +819,14 @@
>   use in the body of a function, but define the function first if the
>   alias has the same name as the function.
>
> +  If you aware of the problem, you can always escape part or all of the
> +  name of the function:
> +  verb(
> +     'l'() { /bin/ls -la "$@" | more }
> +  )
> +  Adding the quotes has no effect on the function definition, but
> +  suppresses alias expansion for the function name.  Hence this is
> +  guaranteed to be safe.

I didn't look up more of the context than what is in the diff hunk, so
maybe this guarantee only holds for aliases of l, but not generally:
% alias l='echo hello'
% alias \'l\'='echo bye'
% l
hello
% 'l'
bye
% 'l'() {print i am a function}
% l
i am a function
% 'l'
i am a function
% "'l'"
zsh: command not found: 'l'
% which l
l: aliased to echo hello
% which 'l'
l: aliased to echo hello
% which "'l'"
'l': aliased to echo bye

What happened at this point:
% 'l'() {print i am a function}

was of course that i defined "echo" (and "bye"):
% which echo
echo () {
	print i am a function
}

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Bug#537596: regression: parse error near `()' in function definition
  2009-07-20  9:10         ` Mikael Magnusson
@ 2009-07-20  9:15           ` Peter Stephenson
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2009-07-20  9:15 UTC (permalink / raw)
  To: zsh-workers

You're right, it's not absolutely guaranteed to be safe.

Index: Etc/FAQ.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Etc/FAQ.yo,v
retrieving revision 1.48
diff -u -r1.48 FAQ.yo
--- Etc/FAQ.yo	20 Jul 2009 09:02:41 -0000	1.48
+++ Etc/FAQ.yo	20 Jul 2009 09:15:07 -0000
@@ -826,7 +826,9 @@
   )
   Adding the quotes has no effect on the function definition, but
   suppresses alias expansion for the function name.  Hence this is
-  guaranteed to be safe.
+  guaranteed to be safe---unless you are in the habit of defining
+  aliases for expressions such as tt('l'), which is valid, but probably
+  confusing.
 
 sect(Similarities with tcsh)
 

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-07-20  9:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20090719171651.GA7217@piper.oerlikon.madduck.net>
2009-07-19 23:20 ` Bug#537596: regression: parse error near `()' in function definition Clint Adams
2009-07-20  4:18   ` Bart Schaefer
2009-07-20  8:27   ` Peter Stephenson
2009-07-20  8:37     ` Mikael Magnusson
2009-07-20  8:50       ` Peter Stephenson
2009-07-20  9:10         ` Mikael Magnusson
2009-07-20  9:15           ` Peter Stephenson
2009-07-20  8:46     ` martin f krafft

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).