Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: odd recursion
- X-seq: zsh-users 8448
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: L:ZSH-users <zsh-users@xxxxxxxxxx>
- Subject: Re: odd recursion
- Date: Tue, 1 Feb 2005 02:48:28 +0000
- In-reply-to: <07053ae70a0e029b3df8b8431dfa6243@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <5ced8dfb84fe26e20350095da48dd44d@xxxxxxxxxxxxxxxxxx> <1ba5918552xff.dlg@xxxxxxxxxxxxxxxx> <6f5f1b5c88ce1d0196392e62bcf981f1@xxxxxxxxxxxxxxxxxx> <41FE98A3.8040700@xxxxxxx> <07053ae70a0e029b3df8b8431dfa6243@xxxxxxxxxxxxxxxxxx>
On Jan 31, 3:30pm, William Scott wrote:
}
} The main point of the question was that I don't see how/why it is a
} recursion, from the logic of the expressions, which is why I said
} there was some sort of fundamental gap in my understanding of how zsh
} works.
There are two bits to this, both of which were touched on in the FAQ
snippet I posted but not really spelled out in detail.
First, the function syntax is not (as you might expect)
name () { body }
Rather, it's
name1 name2 name3 ... () { body }
where name2 name3 ... are optional
Thus it's possible to create a whole set of identical functions in a
single pass. The obscure reason that this is useful is that, when you
setopt FUNCTION_ARGZERO, you can actually have the same function behave
differently depending on its name, just as is sometimes done with C
programs and argv[0].
Second, alias expansion applies to any word in the "command position"
on a command line, BEFORE that command line is parsed. (Global aliases
are another thing entirely.) In the expression
name () { body }
the word "name" is in the command position. Thus the statements
alias name='name arguments'
name () { body }
are equivalent to the single statement
name arguments () { body }
which, depending on the exact statements in "body", might recursively
reference "name" yet again.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author