zsh-workers
 help / color / mirror / code / Atom feed
From: Micah Waddoups <micah@askmicah.net>
To: zsh-workers@zsh.org
Subject: BUG: $_ empty on null function call
Date: Mon, 09 Feb 2015 03:38:58 -0800	[thread overview]
Message-ID: <54D89C52.6050702@askmicah.net> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1648 bytes --]

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 <mailto:micah@askmicah.net>
AskMicah.Net <http://askmicah.net>, Problem Solving Agency

[-- Attachment #1.2: Type: text/html, Size: 2675 bytes --]

             reply	other threads:[~2015-02-09 11:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 11:38 Micah Waddoups [this message]
2015-02-09 11:44 ` Micah Waddoups
2015-02-09 12:20 ` Peter Stephenson
2015-02-09 14:10   ` Daniel Shahaf
2015-02-09 14:25     ` Peter Stephenson
2015-02-09 15:13       ` Peter Stephenson
2015-02-09 16:11         ` Bart Schaefer
2015-02-10 10:59         ` Daniel Shahaf
2015-02-10 10:54       ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54D89C52.6050702@askmicah.net \
    --to=micah@askmicah.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).