zsh-users
 help / color / mirror / code / Atom feed
* Function definitions
@ 2005-06-06  3:23 Meino Christian Cramer
  2005-06-06  4:14 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Meino Christian Cramer @ 2005-06-06  3:23 UTC (permalink / raw)
  To: zsh-users

Hi,

 
 Is there any difference in defining functions like


 function fnord(){
    <blurb>
 }


 or

 fnord(){
    <blurb>
 }


 or

 function fnord{
    <blurb>
 }

 or

 fnord{
    <blurb>
 }

 ?

 (In 'man zshall' I found nothing appropiate...)

 Keep zshing!
 Meino


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

* Re: Function definitions
  2005-06-06  3:23 Function definitions Meino Christian Cramer
@ 2005-06-06  4:14 ` Bart Schaefer
  2005-06-06 15:37   ` Meino Christian Cramer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2005-06-06  4:14 UTC (permalink / raw)
  To: zsh-users

On Jun 6,  5:23am, Meino Christian Cramer wrote:
>  
>  Is there any difference in defining functions like

In zsh there is no difference whether you use the "function" keyword or
not, but in ksh the variable scoping rules are different for definitions
that use it.  So be careful if you have any intention of porting.

I prefer to use "function" because it avoids problems with function and
alias names clashing.

However:

>  function fnord(){
>  fnord(){

Those two are OK and do what you expect, but you should get used to
putting spaces before the empty parens and before the open-brace, because
even though zsh does not always enforce it, the grammar does say that the
spaces should be there, and it's crucial to this next example:

>  function fnord{

That defines a function named "fnord{" whose body will consist of the next
single command seen (*not* up to a matching close-brace).  If you add a
space ...

  function fnord {

... then *that* does what you meant.

>  fnord{

This is a *call* to the function named "fnord{".  Even with a space ...

  fnord {

... is not a definition, it's a *call* to the "fnord" function with the
argument "{".  You must have either the keyword "function" or the empty
parens to make a definition.  I believe using both is a syntax error in
ksh, although zsh allows it.

> (In 'man zshall' I found nothing appropiate...)

In the COMPLEX COMMANDS section:

       function word ... [ () ] [ term ] { list }
       word ... () [ term ] { list }
       word ... () [ term ] command
              where term is one or more newline or ;.  Define a function
              which is referenced by any one of word.


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

* Re: Function definitions
  2005-06-06  4:14 ` Bart Schaefer
@ 2005-06-06 15:37   ` Meino Christian Cramer
  0 siblings, 0 replies; 3+ messages in thread
From: Meino Christian Cramer @ 2005-06-06 15:37 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-users

From: Bart Schaefer <schaefer@brasslantern.com>
Subject: Re: Function definitions
Date: Mon, 06 Jun 2005 04:14:49 +0000

Hi Bart !

 THANKS a LOT for that enlightment ! :)

 Far better than what I saw (but not understood in that extent as you
 have explained it!!!).

 With "I found nothing appropiate" I meant exactly this! 
 I _saw_ words from that context...but...I _understood_ what Bart
 wrotes!!!

 :O)

 Keep zshing!  (<<- that words reminds me of the sound of opening a
			   bottle fresh beer...;)
 Meino
 

> On Jun 6,  5:23am, Meino Christian Cramer wrote:
> >  
> >  Is there any difference in defining functions like
> 
> In zsh there is no difference whether you use the "function" keyword or
> not, but in ksh the variable scoping rules are different for definitions
> that use it.  So be careful if you have any intention of porting.
> 
> I prefer to use "function" because it avoids problems with function and
> alias names clashing.
> 
> However:
> 
> >  function fnord(){
> >  fnord(){
> 
> Those two are OK and do what you expect, but you should get used to
> putting spaces before the empty parens and before the open-brace, because
> even though zsh does not always enforce it, the grammar does say that the
> spaces should be there, and it's crucial to this next example:
> 
> >  function fnord{
> 
> That defines a function named "fnord{" whose body will consist of the next
> single command seen (*not* up to a matching close-brace).  If you add a
> space ...
> 
>   function fnord {
> 
> ... then *that* does what you meant.
> 
> >  fnord{
> 
> This is a *call* to the function named "fnord{".  Even with a space ...
> 
>   fnord {
> 
> ... is not a definition, it's a *call* to the "fnord" function with the
> argument "{".  You must have either the keyword "function" or the empty
> parens to make a definition.  I believe using both is a syntax error in
> ksh, although zsh allows it.
> 
> > (In 'man zshall' I found nothing appropiate...)
> 
> In the COMPLEX COMMANDS section:
> 
>        function word ... [ () ] [ term ] { list }
>        word ... () [ term ] { list }
>        word ... () [ term ] command
>               where term is one or more newline or ;.  Define a function
>               which is referenced by any one of word.
> 


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

end of thread, other threads:[~2005-06-06 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-06  3:23 Function definitions Meino Christian Cramer
2005-06-06  4:14 ` Bart Schaefer
2005-06-06 15:37   ` Meino Christian Cramer

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).