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

Re: odd recursion



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