From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Function definitions
Date: Mon, 06 Jun 2005 04:14:49 +0000 [thread overview]
Message-ID: <1050606041449.ZM21454@candle.brasslantern.com> (raw)
In-Reply-To: <20050606.052350.41178724.Meino.Cramer@gmx.de>
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.
next prev parent reply other threads:[~2005-06-06 4:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-06 3:23 Meino Christian Cramer
2005-06-06 4:14 ` Bart Schaefer [this message]
2005-06-06 15:37 ` Meino Christian Cramer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1050606041449.ZM21454@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).