From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14263 invoked by alias); 10 Feb 2015 10:59:46 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34493 Received: (qmail 13004 invoked from network); 10 Feb 2015 10:59:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=mesmtp; bh=o2pNqSfHZHu huzhkG8gwbEgvapM=; b=PXruKjl8Nhsahxe3DqyXuYWtiU8YE/t5eFkQFaSFgPF EyEmHFUBbCXTYOCxZlGfq1p2zrXJAphpzFlVcoanTmnubdYDEktD5rT0Bdwihemi gOGQ0OCqDi/PnvrOpVq+Qoic1L9z9Pj6ZW8rhjOn9N7Q9WiXeLqA9Y4ASHDC/CKU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:date:from:to:cc:subject :message-id:references:mime-version:content-type :content-transfer-encoding:in-reply-to; s=smtpout; bh=o2pNqSfHZH uhuzhkG8gwbEgvapM=; b=FaX6AdjNLKqKP0RZlR25E2LiSB366AiTePbSOM3Epe aysXYRDUasciinlmmoddQIENIVvGR5Qf8qbdHmKGh5Tmdyvu075zBnVIVj0tL+e5 l3FEYPCjZGdN8Wo8sF3CeAiyRCsvK7vpGsoq4213HGJ5NN6P2bh3WLEm4Nz54rFc M= X-Sasl-enc: DVmbhHQYbc8nxTL58LTj5AEoYm+TLiVooZG/Ym1y8fA3 1423565980 Date: Tue, 10 Feb 2015 10:59:38 +0000 From: Daniel Shahaf To: Peter Stephenson Cc: zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call Message-ID: <20150210105938.GD1834@tarsus.local2> References: <54D89C52.6050702@askmicah.net> <20150209122042.35b74995@pwslap01u.europe.root.pri> <20150209141026.GB1833@tarsus.local2> <20150209142507.348fa42a@pwslap01u.europe.root.pri> <20150209151340.589909be@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150209151340.589909be@pwslap01u.europe.root.pri> User-Agent: Mutt/1.5.21 (2010-09-15) --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 --cNdxnHkX5QqsyA0e Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="anonfunc-dollarunderscore.diff" diff --git a/Src/exec.c b/Src/exec.c index 3b0e936..719345e 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4482,6 +4482,11 @@ execfuncdef(Estate state, Eprog redir_prog) shf->node.nam = "(anon)"; pushnode(args, shf->node.nam); + /* Set up special parameter $_ */ + setunderscore((args && nonempty(args)) + ? ((char *) getdata(lastnode(args))) + : ""); + execshfunc(shf, args); ret = lastval; --cNdxnHkX5QqsyA0e--