POSIX does not mandate any behavior for case F unless one treats
anonymous functions as compound commands
I think POSIX indirectly mandates the behavior. So far, there are two proposals on how to specify anonymous functions:
A) a function call (to a function defined on the spot and undefined right after the call)
B) a compound command
POSIX mandates the behavior for both, function calls and compound commands. Therefore, if we opt for one of these two specifications, POSIX also indirectly mandates the behavior of anonymous functions.
In my opinion, the name and the description of anonymous functions strongly suggests that anonymous functions are a shorthand for defining a function, calling it with the provided arguments, and undefining the function. I have always assumed that "() { <body> } <args>" is syntactic sugar for "anon() { <body> }; { anon <args> } always { unfunction anon }". As far as I can tell, Zsh effectively implements anonymous functions with function calls. If this is indeed the case and one agrees with the specification described here, then everything is consistent; anonymous functions look, feel, and behave like function calls, including when it comes to ERR_EXIT, and this with and without my patches.
You propose to specify anonymous functions as a kind of compound command. This is of course possible but it's not how anonymous functions currently behave. As far as I can tell, they currently behave in all aspects, including ERR_EXIT, as function calls. For ERR_EXIT, see case E, which behaves like the equivalent function call (case H) and not like the equivalent compound command (case B). Note that this is true with and without my patch. Beside the new behavior for ERR_EXIT are there other aspects of anonymous functions that would/should change? If not, is that change of specification really worth it? I fear that anonymous functions as compound commands require a more complicated mental model than anonymous functions as function calls. For example, if anonymous functions are compound commands then I would expect that the "return" in the code below exits the function "foo" but that's not what it does.
foo() {
echo foo-start;
() { echo args: $@; return } 1 2 3
echo foo-end;
}
foo
My feeling is that changing anonymous functions to behave like compound commands adds complexity for little benefit. If it's all about the ERR_EXIT behavior, does that really matter that much? Is there a use case for anonymous functions where the compound command ERR_EXIT behavior is significantly better than the function call ERR_EXIT behavior?
I'd also prefer to post all your patches at once because you attached
them all to the same zsh-workers article. Convention has been that a
series of patches should be sent as a series of articles.
OK, then I will resend my patches in separate emails. This way I can better document what each one is doing. It will also be easier for you (or whoever submits patches) to sooner submit the less controversial ones while the more controversial ones remain open for discussion.
I don't think there's any requirement that the NEWS item arrive at the
same time as the other three patches. We sometimes don't add NEWS
until the time of a release, months (years) after a patch was pushed
to sourceforge git.
I see. In that case I will start another thread with a patch for the NEWS item where we can discuss the exact wording.
Philippe