zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: regression in ${##""}
Date: Fri, 3 Jun 2011 21:16:23 +0100	[thread overview]
Message-ID: <20110603211623.79e653c6@pws-pc.ntlworld.com> (raw)
In-Reply-To: <BANLkTinWR8LuiQiHoVNABB2uuMt_U4d3TQ@mail.gmail.com>

On Fri, 3 Jun 2011 20:55:00 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> > $ ./Src/zsh -c 'set a b; echo ${##""}'
> > zsh:1: bad substitution
> 
> Not a surprise, this is due to
> 
> 28889: ${##} should return the length of $#

Indeed.  How not to define a language, lesson 1:  make the same
symbol have three different meanings in a single expression.

I confess that zsh's own parameter syntax is actually starting to look
rather more attractive... just not very.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.124
diff -p -u -r1.124 subst.c
--- Src/subst.c	23 May 2011 16:08:47 -0000	1.124
+++ Src/subst.c	3 Jun 2011 20:13:21 -0000
@@ -2080,7 +2080,16 @@ paramsubst(LinkList l, LinkNode n, char 
 		    || (cc = s[1]) == '*' || cc == Star || cc == '@'
 		    || cc == '?' || cc == Quest
 		    || cc == '$' || cc == String || cc == Qstring
-		    || cc == '#' || cc == Pound
+		    /*
+		     * Me And My Squiggle:
+		     * ${##} is the length of $#, but ${##foo}
+		     * is $# with a "foo" removed from the start.
+		     * If someone had defined the *@!@! language
+		     * properly in the first place we wouldn't
+		     * have this nonsense.
+		     */
+		    || ((cc == '#' || cc == Pound) &&
+			s[2] == Outbrace)
 		    || cc == '-' || (cc == ':' && s[2] == '-')
 		    || (isstring(cc) && (s[2] == Inbrace || s[2] == Inpar)))) {
 	    getlen = 1 + whichlen, s++;
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.57
diff -p -u -r1.57 D04parameter.ztst
--- Test/D04parameter.ztst	19 May 2011 16:24:38 -0000	1.57
+++ Test/D04parameter.ztst	3 Jun 2011 20:13:21 -0000
@@ -179,9 +179,17 @@
   print ${##}
   set 1 2 3 4 5 6 7 8 9 10
   print ${##}
-0:${##} is length of $#
+  print ${##""}
+  print ${##1}
+  print ${##2}
+  print ${###<->} # oh, for pete's sake...
+0:${##} is length of $#, and other tales of hash horror
 >1
 >2
+>10
+>0
+>10
+>
 
   array=(once bitten twice shy)
   print IF${array}THEN


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      parent reply	other threads:[~2011-06-03 20:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 18:00 Eric Blake
2011-06-03 18:55 ` Mikael Magnusson
2011-06-03 19:16   ` Eric Blake
2011-06-03 20:16   ` Peter Stephenson [this message]

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=20110603211623.79e653c6@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --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).