Peter Stephenson wrote on Mon, Feb 09, 2015 at 15:13:40 +0000: > On Mon, 9 Feb 2015 14:25:07 +0000 > Peter Stephenson wrote: > > On Mon, 9 Feb 2015 14:10:26 +0000 > > Daniel Shahaf wrote: > > > There are some other differences between anonymous functions, e.g., they > > > don't honor PRINT_EXIT_VALUE: > > > > > > Engineering-wise, the ideal solution would be for anonymous and named > > > functions to share code... though I realize that may be a somewhat > > > invasive code change. > > > > They already do everywhere that doesn't deal with the special argument > > syntax (Micah's problem) or with immediate execution after a definition. > > I suspect this may have to do with a different path owing to an > > optimisation later in the execution path where we make certain > > assumptions if code is regarded as "simple". > > Sigh. It's a combination of that *and* execution immediately after > definition. > > When the code is parsed, we don't know if PRINTEXITVALUE is going to be > set when it's run. At this point I think we declare "simple" code > execution for anonymous functions dead in the water. The effect is > probably small anyway. > I was looking at making [[ honor PRINT_EXIT_VALUE; right now it doesn't, because it uses execlist->execsimple->execcond (and so never passes through execcmd). I'm mentioning that since it may be relevant, as it also concerns a simple command wanting to honor PRINT_EXIT_VALUE. ¹ The use-case: I use [[ ]] as a standalone command (not as part of an if or while) in interactive shells to test its syntax when writing scripts. > It looks like we can make some code in the lowest level of general > command execution, execcmd(), run in a few more cases, at least the > following attempt to move them out of an if block doesn't cause any test > failures. > > This doesn't help with Micah's problem which is due to the *third* > difference. > I'll just point out for anyone who needs $_ with anonymous functions working "yesterday" that a quick and dirty way to achieve that is via the attached patch. It might not be a good general solution since it duplicates code, but it does make invocation of anonymous functions set $_ and I think it has no harmful effects. I suppose a better fix would involve extracting the arguments of an anonymous function up in execcmd() rather than down in execfuncdef(), so they can reuse the existing setunderscore() call in execcmd()? > + () { false; } > +1:PRINT_EXIT_VALUE option for anonymous function > +?zsh: exit 1 Thanks for fixing this :) Daniel