From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21730 invoked by alias); 9 Feb 2015 11:37:03 -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: 34478 Received: (qmail 26784 invoked from network); 9 Feb 2015 11:36:49 -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=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 Message-ID: <54D89C52.6050702@askmicah.net> Date: Mon, 09 Feb 2015 03:38:58 -0800 From: Micah Waddoups User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: BUG: $_ empty on null function call Content-Type: multipart/mixed; boundary="------------080208060509050508000907" X-Provags-ID: V02:K0:kvvSa0/JbS6cfAv1bv+YpEifYC/GoZWuO0VE3QiD6Yy NCSJXwocpqrXckbBuzioEMS2CyyQgNGGUrWJy14qiSC9vUYJTk owYh3EwXX18Yqi+QWiNY7DUMyBCTzdz29tQO9heUJQ9Tkchp4y CipqmYNyej9Obg+z2bV3UlHIx+5NxxfvYpdugSsCXxtVKXkZiP d4Z7r3xD5DzTmjca/8W5ZDHMw/wmSVB0YL06WIQ4peAL/NvCtY XYu0ApoESUpDSUcpeyaO1fhvtDSOsPw72Unf+So2gr589r20fT 5QsWF7njFFkNinQLuKYhGQzGIQyUGF9S8DYz1yu4vuV3d1FFpg 2zM1bweoxD4/SkBhct4yOydOA3hmThAaIFfyalgRl X-UI-Out-Filterresults: notjunk:1; --------------080208060509050508000907 Content-Type: multipart/alternative; boundary="------------010706090207080406080401" --------------010706090207080406080401 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello all, I am still a beginner in developing, or I would tackle this issue directly myself. The misbehavior is when the command list has a null function with parameters, the last-command-last-parameter ($_) built-in variable goes blank. Example: |local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; } $_ Three; print -l $_ Four; ## Should print: # Two # One # Three # Three # Four ## Currently prints: # Two # Three # Four ## Conversely, when no arguments are given to the null function, ## it operates mostly normally, but as if the function were not there:| ||local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; }; print -l $_ Four;| ## Outputs: # Two # # One # Four ## ( second line is 'print -l' but $argv is empty | It would seem this unexpected behavior may be the result of an unfinished shell source where the best shell behavior was not clear to the programmer. I admit dealing with null functions is a minor point of dilema with script writing, but I have gotten super intricate with the beautiful script design and features made available to me by ZSH, and I have found that the behavior suggested at "Should print" above is the only way that is consistent in a large script where an alias may use a null function for better handling of parameters without interfering with any currently same-name functions, or when a Heredoc is used and one wants to grab the last argument to use as the parameter of an immediately following null function. -- Micah micah@askmicah.net AskMicah.Net , Problem Solving Agency --------------010706090207080406080401 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hello all,
  I am still a beginner in developing, or I would tackle this issue directly myself.  The misbehavior is when the command list has a null function with parameters, the last-command-last-parameter ($_) built-in variable goes blank.  Example:

local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; } $_ Three; print -l $_ Four;
## Should print:
#  Two
#  One
#  Three
#  Three
#  Four

## Currently prints:
#  Two
#  Three
#  Four

## Conversely, when no arguments are given to the null function,
## it operates mostly normally, but as if the function were not there:

local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; }; print -l $_ Four;
## Outputs:
#  Two
# 
#  One
#  Four
##     ( second line is 'print -l' but $argv is empty

  It would seem this unexpected behavior may be the result of an unfinished shell source where the best shell behavior was not clear to the programmer.  I admit dealing with null functions is a minor point of dilema with script writing, but I have gotten super intricate with the beautiful script design and features made available to me by ZSH, and I have found that the behavior suggested at "Should print" above is the only way that is consistent in a large script where an alias may use a null function for better handling of parameters without interfering with any currently same-name functions, or when a Heredoc is used and one wants to grab the last argument to use as the parameter of an immediately following null function.

--
Micah micah@askmicah.net
AskMicah.Net, Problem Solving Agency
--------------010706090207080406080401-- --------------080208060509050508000907-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13831 invoked by alias); 9 Feb 2015 11:42:07 -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: 34479 Received: (qmail 2238 invoked from network); 9 Feb 2015 11:42:05 -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=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 Message-ID: <54D89D8F.8090706@askmicah.net> Date: Mon, 09 Feb 2015 03:44:15 -0800 From: Micah Waddoups User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call References: <54D89C52.6050702@askmicah.net> In-Reply-To: <54D89C52.6050702@askmicah.net> Content-Type: multipart/mixed; boundary="------------070101020004070500030708" X-Provags-ID: V02:K0:RdM6OzMIjAIjz4q7U2ZEOmAPd1VvwqbchsLWVZwmC1r tg0l1CIXvVw2B0ODnxA2J37jQvCh2t7WvQjjbhk9L+ySeMjrPb p9/g3iBTCXOf+Ikxg+xMVV8+zLrKAnt7jPVWKTjQ/m5uqcv3Hr MAhbPhVJpwt7ooOq2vKjMPiZnCfy7BNN6ihlQiPJfWgTVaZl35 fsPrGMWaTq7rZV/NrtUi44U2EIcs/4s/t84GubZD/hBV7z77vc fTSPdS4RGLYlbtyPhNqza6Dsk+0U59Se+S+zUaZv9vKTQyv/sH V+S0HHhtxgDh18xXewQRG/os/Pi7KPUXDx13BA70wtndPbCBVX D7IZUdaWcVjjdcZBG7XGpIKC/EQoaaLplocoKLFsP X-UI-Out-Filterresults: notjunk:1; --------------070101020004070500030708 Content-Type: multipart/alternative; boundary="------------050902090606070803020704" --------------050902090606070803020704 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Again, please show mercy on me in my innexperience. The current patch-level of the ZSH shell I am using is: zsh-5.0.7-0-g208bded It is the standard "Arch Linux" zsh package as of January 2015. On 02/09/2015 03:38 AM, Micah Waddoups wrote: > Hello all, > I am still a beginner in developing, or I would tackle this issue > directly myself. The misbehavior is when the command list has a null > function with parameters, the last-command-last-parameter ($_) > built-in variable goes blank. Example: > > |local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; > } $_ Three; print -l $_ Four; > ## Should print: > # Two > # One > # Three > # Three > # Four > > ## Currently prints: > # Two > # Three > # Four > > ## Conversely, when no arguments are given to the null function, > ## it operates mostly normally, but as if the function were not there:| > ||local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; > }; print -l $_ Four;| > ## Outputs: > # Two > # > # One > # Four > ## ( second line is 'print -l' but $argv is empty > | > > It would seem this unexpected behavior may be the result of an > unfinished shell source where the best shell behavior was not clear to > the programmer. I admit dealing with null functions is a minor point > of dilema with script writing, but I have gotten super intricate with > the beautiful script design and features made available to me by ZSH, > and I have found that the behavior suggested at "Should print" above > is the only way that is consistent in a large script where an alias > may use a null function for better handling of parameters without > interfering with any currently same-name functions, or when a Heredoc > is used and one wants to grab the last argument to use as the > parameter of an immediately following null function. > > -- > Micah micah@askmicah.net > AskMicah.Net , Problem Solving Agency -- Micah micah@askmicah.net AskMicah.Net , Problem Solving Agency --------------050902090606070803020704 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Again, please show mercy on me in my innexperience.  The current patch-level of the ZSH shell I am using is:
   zsh-5.0.7-0-g208bded
It is the standard "Arch Linux" zsh package as of January 2015.


On 02/09/2015 03:38 AM, Micah Waddoups wrote:
Hello all,
  I am still a beginner in developing, or I would tackle this issue directly myself.  The misbehavior is when the command list has a null function with parameters, the last-command-last-parameter ($_) built-in variable goes blank.  Example:

local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; } $_ Three; print -l $_ Four;
## Should print:
#  Two
#  One
#  Three
#  Three
#  Four

## Currently prints:
#  Two
#  Three
#  Four

## Conversely, when no arguments are given to the null function,
## it operates mostly normally, but as if the function were not there:

local a=1 b=2 c=3; : One; function { : Two; echo $_; print -l $argv; }; print -l $_ Four;
## Outputs:
#  Two
# 
#  One
#  Four
##     ( second line is 'print -l' but $argv is empty

  It would seem this unexpected behavior may be the result of an unfinished shell source where the best shell behavior was not clear to the programmer.  I admit dealing with null functions is a minor point of dilema with script writing, but I have gotten super intricate with the beautiful script design and features made available to me by ZSH, and I have found that the behavior suggested at "Should print" above is the only way that is consistent in a large script where an alias may use a null function for better handling of parameters without interfering with any currently same-name functions, or when a Heredoc is used and one wants to grab the last argument to use as the parameter of an immediately following null function.

--
Micah micah@askmicah.net
AskMicah.Net, Problem Solving Agency

--
Micah micah@askmicah.net
AskMicah.Net, Problem Solving Agency
--------------050902090606070803020704-- --------------070101020004070500030708-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14371 invoked by alias); 9 Feb 2015 12:20:51 -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: 34480 Received: (qmail 27485 invoked from network); 9 Feb 2015 12:20:48 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7fc86d0000066b7-63-54d8a58ae39a Date: Mon, 09 Feb 2015 12:20:42 +0000 From: Peter Stephenson To: Micah Waddoups , zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call Message-id: <20150209122042.35b74995@pwslap01u.europe.root.pri> In-reply-to: <54D89C52.6050702@askmicah.net> References: <54D89C52.6050702@askmicah.net> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDLMWRmVeSWpSXmKPExsVy+t/xq7pdS2+EGDw8oWmx7vFJFouDzQ+Z HJg8Fu7rYPdYdfADUwBTFJdNSmpOZllqkb5dAlfGpxX+BY+YKw6eNG5gbGTuYuTgkBAwkZix uLqLkRPIFJO4cG89WxcjF4eQwFJGiRvnfrFAOD1MEuf6X7JCONsYJc7NX8gM0sIioCqx7vdS JhCbTcBQYuqm2YwgtoiAjcTeO/NYQWxhAQOJJze+soHYvAL2EtcffGID2cwpoCNxbK89SFhI QFvix6QNLCA2v4C+xNW/n5ggLrKXmHnlDCNEq6DEj8n3wGqYBbQkNm9rYoWw5SU2r3nLDDFH XeLG3d3sExiFZiFpmYWkZRaSlgWMzKsYRVNLkwuKk9JzjfSKE3OLS/PS9ZLzczcxQkL46w7G pcesDjEKcDAq8fBaKF8PEWJNLCuuzD3EKMHBrCTCawqMACHelMTKqtSi/Pii0pzU4kOMTByc Ug2MaVLnKj0n/14ucejn/tsZVr9ftFrycS3vyn432UctdM2hSSFKN5oXC4gnmlh+ELi7xtj3 08zPKy+s22M39V7n3H8nz/i2t0kty9RzsvlofZ735dPuM5dcX3D47LE7dXDym8+ZEuGz7JKm CPcJXGc9ZXftWMfa0HOHJA4KKcvtn7KbbVqAmbVhsRJLcUaioRZzUXEiAJMk9kE/AgAA On Mon, 9 Feb 2015 03:38:58 -0800 Micah Waddoups wrote: > I am still a beginner in developing, or I would tackle this issue > directly myself. The misbehavior is when the command list has a null > function with parameters, the last-command-last-parameter ($_) built-in > variable goes blank. Yes, that's obviously an oversight internally. $_ simply isn't handled on this path. Somebody will get around to it eventually, I imagine... pws From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24447 invoked by alias); 9 Feb 2015 14:10:34 -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: 34483 Received: (qmail 896 invoked from network); 9 Feb 2015 14:10:33 -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:in-reply-to; s= mesmtp; bh=DCp2E4YKxF/s5hdH2r+m1ulChSc=; b=xOpCkQxSDXYf/JjtvQGy7 fGXOBQ0hyjV5pjLxw4Lp3rReyAu0UE7BfF0Vgvde9/ghAHjhG3hXYVtmo8yyfZdJ 6dQ7XJOHiWyedYWnvyOvaE7viTCGZTMsPoxfr2aO6tWAWUX7uREU+qpfCsH+lTcy THhBYDSIg+CZDELm/81/s8= 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:in-reply-to; s= smtpout; bh=DCp2E4YKxF/s5hdH2r+m1ulChSc=; b=MiILIsAcli0AZ1WsCu1E /KvGxwhyEEoNK4OwwAFRsfeXKbuH/HLnqEIvmQ5p29oO8eFHUI+r/UVWcCjVJFrf XF9VuSBxGFEpGnLuJvCbnzeb+e02QPeL7PBRTiMi0MbdA0HEXa4wvtUFtRnzELoV 5koZPTx1kLRSnnLs/9sfnlo= X-Sasl-enc: 7mk2vyCAlMElFglfYzrGwAw1ddKQORjd61cq0S0wjjxf 1423491031 Date: Mon, 9 Feb 2015 14:10:26 +0000 From: Daniel Shahaf To: Peter Stephenson Cc: Micah Waddoups , zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call Message-ID: <20150209141026.GB1833@tarsus.local2> References: <54D89C52.6050702@askmicah.net> <20150209122042.35b74995@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150209122042.35b74995@pwslap01u.europe.root.pri> User-Agent: Mutt/1.5.21 (2010-09-15) Peter Stephenson wrote on Mon, Feb 09, 2015 at 12:20:42 +0000: > On Mon, 9 Feb 2015 03:38:58 -0800 > Micah Waddoups wrote: > > I am still a beginner in developing, or I would tackle this issue > > directly myself. The misbehavior is when the command list has a null > > function with parameters, the last-command-last-parameter ($_) built-in > > variable goes blank. > > Yes, that's obviously an oversight internally. $_ simply isn't handled > on this path. > There are some other differences between anonymous functions, e.g., they don't honor PRINT_EXIT_VALUE: % setopt printexitvalue % () false v. % setopt printexitvalue % f() false % f zsh: exit 1 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. Daniel > Somebody will get around to it eventually, I imagine... > > pws From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6838 invoked by alias); 9 Feb 2015 14:35:28 -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: 34484 Received: (qmail 2654 invoked from network); 9 Feb 2015 14:35:16 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7fc86d0000066b7-1b-54d8c2b2d153 Date: Mon, 09 Feb 2015 14:25:07 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call Message-id: <20150209142507.348fa42a@pwslap01u.europe.root.pri> In-reply-to: <20150209141026.GB1833@tarsus.local2> References: <54D89C52.6050702@askmicah.net> <20150209122042.35b74995@pwslap01u.europe.root.pri> <20150209141026.GB1833@tarsus.local2> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjluLIzCtJLcpLzFFi42I5/e/4Vd1Nh26EGMy+oWlxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mm70tTMXbGavuHvyM1sDYxNbFyMnh4SAicSR73tZIGwxiQv3 1gPFuTiEBJYySly4PY8RwlnOJDGxv4MZpIpFQFXizrY+VhCbTcBQYuqm2YwgtoiAuMTZtefB JgkLGEg8ufEVbAOvgL3E0o3bwWo4BYwklm2dygoxtJNRoun+DbAEv4C+xNW/n5ggzrCXmHnl DCNEs6DEj8n3wIYyC2hJbN7WxAphy0tsXvOWeQKjwCwkZbOQlM1CUraAkXkVo2hqaXJBcVJ6 rpFecWJucWleul5yfu4mRkgYft3BuPSY1SFGAQ5GJR5eC+XrIUKsiWXFlbmHGCU4mJVEeE2X 3ggR4k1JrKxKLcqPLyrNSS0+xMjEwSnVwKgXtyCcKb2cT0kl917xLIerGmk7N0nnffA3CjNm PrhXjFehJOBaUVJPrskStWu5Yms7mEps5733unVMmPdCmVCc9sQAEQ+3wie7zH6/tfK1D9rq tk7g0ATDcAOb/pIGuaqj/9anXd9vrKB44rp/xuR3T2o/edbs//iwnClYa3H73Jm2sWlPlViK MxINtZiLihMBFbtz2SECAAA= 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". This is inevitably a maintenance headache and we've had lots of issues there. By the way, if that means you're interested in looking at the internals, please do... suggestions based on this are much more likely to be useful, for obvious reasons. pws From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5029 invoked by alias); 9 Feb 2015 15:24:00 -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: 34485 Received: (qmail 29661 invoked from network); 9 Feb 2015 15:23:48 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-1e-54d8ce16c012 Date: Mon, 09 Feb 2015 15:13:40 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call Message-id: <20150209151340.589909be@pwslap01u.europe.root.pri> In-reply-to: <20150209142507.348fa42a@pwslap01u.europe.root.pri> References: <54D89C52.6050702@askmicah.net> <20150209122042.35b74995@pwslap01u.europe.root.pri> <20150209141026.GB1833@tarsus.local2> <20150209142507.348fa42a@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrMLMWRmVeSWpSXmKPExsVy+t/xa7pi526EGOx+zWNxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mq6fkS04o1Px4/1G1gbGv4pdjJwcEgImEg9/NbFA2GISF+6t ZwOxhQSWMkpMW+vUxcgFZC9hkmg4/JwFwtnGKPFr/np2kCoWAVWJP6evsYLYbAKGElM3zWYE sUUExCXOrj0PNlVYwEDiyY2vQFM5OHgF7CU2L4oGCXMKOEgc+rUEatl+Rokt/0RBbH4BfYmr fz8xQRxkLzHzyhmwkbwCghI/Jt8DG8ksoCWxeVsTK4QtL7F5zVtmiDnqEjfu7mafwCg0C0nL LCQts5C0LGBkXsUomlqaXFCclJ5rqFecmFtcmpeul5yfu4kRErBfdjAuPmZ1iFGAg1GJh9dC +XqIEGtiWXFl7iFGCQ5mJRHeH2duhAjxpiRWVqUW5ccXleakFh9iZOLglGpgtO78fELKILu4 Iexm0J/282bPVwQ/lD438bgH78cDnjdd1l3tjRBd9vZIUnBtWMqtQH/RB4LnJsq3Td++zu6z 4SqGG4pRzB7OD7kYn818sNGy/uXttKOvV2mHl8yN2Rqn/Nbp+DzN1WI9XnPtj3XnPvS8f/mq lCcPu6VO55TTEzL1uWU537aYK7EUZyQaajEXFScCAHJpEQU2AgAA 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. 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 suppose saying things like 'does anybody know why PRINTEXITVALUE only works if the shell is executing code from standard input' is a bit pointless? It's documented as "only at the command line in interactive shells", but that's not actually how it's implemented. diff --git a/Src/exec.c b/Src/exec.c index 3b0e936..992bd08 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2427,6 +2427,7 @@ execcmd(Estate state, int input, int output, int how, int last1) wordcode code; Wordcode beg = state->pc, varspc; FILE *oxtrerr = xtrerr, *newxtrerr = NULL; + LinkList restorelist = 0, removelist = 0; doneps4 = 0; redir = (wc_code(*state->pc) == WC_REDIR ? ecgetredirs(state) : NULL); @@ -3374,7 +3375,6 @@ execcmd(Estate state, int input, int output, int how, int last1) } else lastval = (execfuncs[type - WC_CURSH])(state, do_exec); } else if (is_builtin || is_shfunc) { - LinkList restorelist = 0, removelist = 0; /* builtin or shell function */ if (!forked && ((cflags & BINF_COMMAND) || @@ -3424,29 +3424,6 @@ execcmd(Estate state, int input, int output, int how, int last1) } else clearerr(stdout); } - if (isset(PRINTEXITVALUE) && isset(SHINSTDIN) && - lastval && !subsh) { -#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD) - fprintf(stderr, "zsh: exit %lld\n", lastval); -#else - fprintf(stderr, "zsh: exit %ld\n", (long)lastval); -#endif - fflush(stderr); - } - - if (do_exec) { - if (subsh) - _exit(lastval); - - /* If we are exec'ing a command, and we are not in a subshell, * - * then check if we should save the history file. */ - if (isset(RCS) && interact && !nohistsave) - savehistfile(NULL, 1, HFILE_USE_OPTIONS); - exit(lastval); - } - if (restorelist) - restore_params(restorelist, removelist); - } else { if (!forked) setiparam("SHLVL", --shlvl); @@ -3496,6 +3473,28 @@ execcmd(Estate state, int input, int output, int how, int last1) execlist(state, 0, 1); } } + if (isset(PRINTEXITVALUE) && isset(SHINSTDIN) && + lastval && !subsh) { +#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD) + fprintf(stderr, "zsh: exit %lld\n", lastval); +#else + fprintf(stderr, "zsh: exit %ld\n", (long)lastval); +#endif + fflush(stderr); + } + + if (do_exec) { + if (subsh) + _exit(lastval); + + /* If we are exec'ing a command, and we are not in a subshell, * + * then check if we should save the history file. */ + if (isset(RCS) && interact && !nohistsave) + savehistfile(NULL, 1, HFILE_USE_OPTIONS); + exit(lastval); + } + if (restorelist) + restore_params(restorelist, removelist); } err: diff --git a/Src/parse.c b/Src/parse.c index 0b54a90..ffd25de 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1612,8 +1612,7 @@ par_funcdef(int *cmplx) num++; zshlex(); } - if (num > 0) - *cmplx = 1; + *cmplx = 1; ecbuf[parg] = ecused - parg; /*?*/ ecbuf[parg+1] = num; } @@ -1897,8 +1896,7 @@ par_simple(int *cmplx, int nr) argc++; zshlex(); } - if (argc > 0) - *cmplx = 1; + *cmplx = 1; ecbuf[parg] = ecused - parg; /*?*/ ecbuf[parg+1] = argc; } diff --git a/Test/E01options.ztst b/Test/E01options.ztst index 46b1837..3213534 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -783,14 +783,24 @@ >print is a shell builtin ?(eval):8: command not found: print -# This option seems to be problematic. I don't quite know how it works. -## func() { -## setopt localoptions printexitvalue -## false -## } -## func -## 1:PRINT_EXIT_VALUE option -## ?(eval):2: exit 1 +# PRINTEXITVALUE only works if shell input is coming from standard input. +# Goodness only knows why. + $ZTST_testdir/../Src/zsh -f <<<' + setopt printexitvalue + func() { + false + } + func + ' +1:PRINT_EXIT_VALUE option +?zsh: exit 1 + + $ZTST_testdir/../Src/zsh -f <<<' + setopt printexitvalue + () { false; } + ' +1:PRINT_EXIT_VALUE option for anonymous function +?zsh: exit 1 setopt promptbang print -P ! From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15494 invoked by alias); 9 Feb 2015 16:12:13 -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: 34486 Received: (qmail 23824 invoked from network); 9 Feb 2015 16:12:11 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=PYxIXZlY c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=0HtSIViG9nkA:10 a=J5c-QLgOSusexWlwlZsA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150209081155.ZM14676@torch.brasslantern.com> Date: Mon, 09 Feb 2015 08:11:55 -0800 In-reply-to: <20150209151340.589909be@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: BUG: $_ empty on null function call" (Feb 9, 3:13pm) 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> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 9, 3:13pm, Peter Stephenson wrote: } } I suppose saying things like 'does anybody know why PRINTEXITVALUE only } works if the shell is executing code from standard input' is a bit } pointless? There seem to be (perhaps "have been" would be more accurate as I think we've changed some of them) several places where SHINSTDIN was used as a placeholder for "stderr is a terminal, therefore we can print this without garbling output that may be going where the user won't see it". From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16091 invoked by alias); 10 Feb 2015 10:54:32 -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: 34492 Received: (qmail 25337 invoked from network); 10 Feb 2015 10:54:19 -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:in-reply-to; s= mesmtp; bh=h29OxWnSeyT0RLhWm1CWe5xO6Hc=; b=RwfM3Gm6BW0MipalACaGS vqm3aujCnoOFsmZZJYHhHiMLLwzn88aai/sgK16a5+9yoHTPHIIWV2NWJlROHgI3 bdYyFotZxz9xaIHaxVUli5M1qhyFtuz9Dt1hfMndrP3Qo9m6IzA8GLTD50RrTmXq jmYhprKK69S8cpOf5K6+XY= 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:in-reply-to; s= smtpout; bh=h29OxWnSeyT0RLhWm1CWe5xO6Hc=; b=iR4DAs6TlS+xH+//SPvl M2xcAiCPK6ZP35SA4XueUMTzB54f4mxDy04E73xk3dvFkjfowtzBN/zqRw5sv4Si HeBHQWb1oKZmm6ZYwZkXSKIVUttTOSyEXQdXjkIkunIcn4YLXuKyglW2RgAX9OnQ 9+p0F2yCpc1zrPC58rqK8Qk= X-Sasl-enc: dJRCjjiOJk4t6YIOi8iwPJkkwIz4hG15GRIvM9o1MKyD 1423565656 Date: Tue, 10 Feb 2015 10:54:14 +0000 From: Daniel Shahaf To: Peter Stephenson Cc: zsh-workers@zsh.org Subject: Re: BUG: $_ empty on null function call Message-ID: <20150210105414.GC1834@tarsus.local2> References: <54D89C52.6050702@askmicah.net> <20150209122042.35b74995@pwslap01u.europe.root.pri> <20150209141026.GB1833@tarsus.local2> <20150209142507.348fa42a@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150209142507.348fa42a@pwslap01u.europe.root.pri> User-Agent: Mutt/1.5.21 (2010-09-15) Peter Stephenson wrote on Mon, Feb 09, 2015 at 14:25:07 +0000: > 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. Sorry, I know they have execshfunc() in common. I was trying to suggest that anonymous functions should start using execcmd(), which named functions were using, in order to reuse its handling of $_ and PRINT_EXIT_VALUE. > 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". This is inevitably a > maintenance headache and we've had lots of issues there. > For what it's worth, "() {} foo bar ; print $_" reproduces Micah's problem and, both before and after your patch, doesn't go through execsimple(). Cheers, Daniel 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--