> > 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 "() { } " is syntactic sugar for "anon() { }; { anon } 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 On Wed, Nov 23, 2022 at 7:59 AM Lawrence Velázquez wrote: > On Mon, Nov 21, 2022, at 9:52 PM, Philippe Altherr wrote: > > To help decide what to do, here is a table that lists all the different > > cases and how they behave in the current Zsh, in a patched Zsh, and in > > a patched Zsh where anonymous functions behave as compound commands: > > > > Code Current Zsh Patched Zsh > > Compound command (and patches) > > A) false Exit Exit Exit > > B) false && true No exit No exit No > > exit > > C) { false && true } No exit No exit No > > exit > > D) () { false } Exit Exit Exit > > E) () { false && true } Exit Exit *No > > exit* > > F) () { { false && true } } No Exit *Exit* > > No exit > > G) f() { false }; f Exit Exit Exit > > H) f() { false && true }; f Exit Exit > > Exit > > I) f() { { false && true } }; f No Exit *Exit* > > *Exit* > > > > Currently anonymous functions behave like function calls. My patches > > don't change that but they change/fix cases F and I to behave as > > mandated by POSIX. > > POSIX does not mandate any behavior for case F unless one treats > anonymous functions as compound commands, in which case the new > behavior actually violates the standard. > > -- > vq >