Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,HDRS_LCASE,
	T_MANY_HDRS_LCASE autolearn=no autolearn_force=no version=3.4.1
X-AuditID: cbfec7f5-f792a6d000001302-e3-577a3c6693ab
Date: Mon, 04 Jul 2016 11:37:23 +0100
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: zcalc tweaks
Message-id: <20160704113723.79be3952@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+NgFtrGLMWRmVeSWpSXmKPExsVy+t/xK7ppNlXhBu9uW1ocbH7I5MDoserg
	B6YAxigum5TUnMyy1CJ9uwSujEV7VzMXPJOsOHJ9NVMD42LhLkZODgkBE4kNJ98wQ9hiEhfu
	rWcDsYUEljJKbJqf38XIBWTPYJKY/eoBO4RzmlFi2fluqKozjBLbzsSC2CwCqhLtr6Yzgdhs
	AoYSUzfNZuxi5OAQEdCWaP8oBhIWFpCRmPj8DiuIzStgLzH/wDuwxfwC+hJX/35igjjCXmLm
	lTOMEDWCEj8m32MBsZkFtCQ2b2tihbDlJTavecsMcYK6xI27u9knMArOQtIyC0nLLCQtCxiZ
	VzGKppYmFxQnpeca6RUn5haX5qXrJefnbmKEhObXHYxLj1kdYhTgYFTi4WWIqQwXYk0sK67M
	PcQowcGsJMI7w7IqXIg3JbGyKrUoP76oNCe1+BCjNAeLkjjvzF3vQ4QE0hNLUrNTUwtSi2Cy
	TBycUg2MERwZrdmnpn10r8ra47D+cK5+YUdb/FO7yc+YvyQ+XbE5VOlMefKnx4LmRR/8LV+W
	Sj7a3f771sG6DZYfS9Su6rh9FNBKqJotf+3BmvjtE8Ma7novMfOO6eme1fkw7l3hC7NVIouO
	d2bfEndh2adwbYmh72LRUk/BjWvduQ9bv+CTbOdlOPRKiaU4I9FQi7moOBEACFmnaUkCAAA=
X-Seq: zsh-workers 38783

Update to the previous set --- decided these were more obvious and
useful ways of interacting with variables.

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index f1208e8..d4a4538 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -3829,16 +3829,24 @@ the stack to be duplicated onto the stack.
 )
 item(tt(pop))(
 The pseudo-function tt(pop) causes the most recent element of
-the stack to be popped.  A `tt(<)' on its own has the same effect.
+the stack to be popped.  A `tt(>)' on its own has the same effect.
+)
+item(tt(>)var(ident))(
+The expression tt(>) followed (with no space) by a shell identifier
+causes the most recent element of the stack to be popped and
+assigned to the variable with that name.  The variable is
+local to the tt(zcalc) function.
 )
 item(tt(<)var(ident))(
 The expression tt(<) followed (with no space) by a shell identifier
-causes the most recent element of the stack to be popped and
-assigned to the identifier.
+causes the value of the variable with that name to be pushed
+onto the stack.  var(ident) may be an integer, in which
+case the previous result with that number (as shown before
+the tt(>) in th standard standard tt(zcalc) prompt) is put on the stack.
 )
 item(Exchange: tt(xy))(
 The pseudo-function tt(xy) causes the most recent two elements of
-the stack to be exchanged.
+the stack to be exchanged.  `tt(<>)' has the same effect.
 )
 enditem()
 
diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc
index 86b1e4a..4803733 100644
--- a/Functions/Misc/zcalc
+++ b/Functions/Misc/zcalc
@@ -94,7 +94,7 @@
 # sequentially just as if read automatically.
 
 emulate -L zsh
-setopt extendedglob
+setopt extendedglob typesetsilent
 
 zcalc_show_value() {
   if [[ -n $_base ]]; then
@@ -301,7 +301,7 @@ while (( _expression_mode )) ||
     ;;
 
     ((:|)local([[:blank:]]##*|))
-      eval $_line
+      eval ${_line##:}
       _line=
       continue
     ;;
@@ -333,7 +333,11 @@ while (( _expression_mode )) ||
 	_push=1
 	_matched=1
 	case $_line in
-	  (\=|pop|\<[[:IDENT:]]#)
+	  (\<[[:IDENT:]]##)
+	  ans=${(P)${_line##\<}}
+	  ;;
+
+	  (\=|pop|\>[[:IDENT:]]#)
 	  if (( ${#stack} < 1 )); then
 	    print -r -- "${_line}: not enough values on stack" >&2
 	    _line=
@@ -343,12 +347,18 @@ while (( _expression_mode )) ||
 	    (=)
 	    ans=${stack[1]}
 	    ;;
-	    (pop|\<)
+	    (pop|\>)
 	    _push=0
 	    shift stack
 	    ;;
-	    (\<[[:IDENT:]]##)
-	    (( ${_line##\<} = ${stack[1]} ))
+	    (\>[[:IDENT:]]##)
+	    if [[ ${_line##\>} = (_*|stack|ans|PI|E) ]]; then
+	      print "${_line##\>}: reserved variable" >&2
+	      _line=
+	      continue
+	    fi
+	    local ${_line##\>}
+	    (( ${_line##\>} = ${stack[1]} ))
 	    _push=0
 	    shift stack
 	    ;;
@@ -371,14 +381,14 @@ while (( _expression_mode )) ||
 	  shift 2 stack
 	  ;;
 
-	  (ldexp|jn|yn|scalb|xy)
+	  (ldexp|jn|yn|scalb|xy|\<\>)
 	  # Functions with two arguments
 	  if (( ${#stack} < 2 )); then
 	    print -r -- "${_line}: not enough values on stack" >&2
 	    _line=
 	    continue
 	  fi
-	  if [[ $_line = xy ]]; then
+	  if [[ $_line = (xy|\<\>) ]]; then
 	    _tmp=${stack[1]}
 	    stack[1]=${stack[2]}
 	    stack[2]=$_tmp

