zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org (Zsh hackers list)
Subject: Re: PATCH: bash-style substrings & subarrays
Date: Sat, 20 Nov 2010 21:15:28 +0000	[thread overview]
Message-ID: <20101120211528.0caf8697@pws-pc.ntlworld.com> (raw)
In-Reply-To: <101119100147.ZM4622@torch.brasslantern.com>

On Fri, 19 Nov 2010 10:01:45 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Nov 17,  4:54pm, Peter Stephenson wrote:
> }
> } This implements the ${NAME:OFFSET} and ${NAME:OFFSET:LENGTH} syntax.
> } This is basically for compatibility; we don't need the extra
> } functionality, but it's a syntax people are nowadays assuming they can
> } use.
> 
> I'm wondering whether :OFFSET:LENGTH shouldn't always use KSH_ARRAYS
> semantics, or be a valid syntax only when KSH_ARRAYS is set?  If it's
> for compatibility with people who are assuming it works, those people
> are also going to assume it has zero-offset, aren't they?

I can see that if you interpret the word "OFFSET" literally it's
different from a subscript and you might interpret it as starting from 0
in any case.  I still think on balance consistency with normal
subscripting is preferable.  I don't think half-measures compatibility
with other shells is particularly useful, in the end is probably more
confusing when you find some things work the way you expect and some
things don't.  However, with a stress in the documentation on the fact
that it's an offset, not a subscript, I can see there's an argument for
the other way.

> There may be some error cases not yet caught:
> 
> schaefer<508> foo=123456789
> schaefer<509> unset y x
> schaefer<510> echo ${foo:$y:$x} 
> zsh: bad math expression: illegal character: Ý
> 
> That Ý looks like uninitialized memory garbage.

It's the fact that empty strings turn into Nularg. I should be tidying
up the string after the expansion.  After the patch empty expansions evaluate
to 0, consistent with the effect of 

% print $(( ))
0

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.110
diff -p -u -r1.110 subst.c
--- Src/subst.c	18 Nov 2010 13:57:19 -0000	1.110
+++ Src/subst.c	20 Nov 2010 20:58:22 -0000
@@ -1403,6 +1403,8 @@ check_colon_subscript(char *str, char **
     if (parsestr(str = dupstring(str)))
 	return NULL;
     singsub(&str);
+    remnulargs(str);
+    untokenize(str);
 
     **endp = sav;
     return str;

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


  reply	other threads:[~2010-11-20 22:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17 16:54 Peter Stephenson
2010-11-18 12:44 ` Peter Stephenson
2010-11-19 18:01 ` Bart Schaefer
2010-11-20 21:15   ` Peter Stephenson [this message]
2010-11-21  6:34     ` Bart Schaefer
2010-11-21 17:02       ` Peter Stephenson
2010-11-21 20:11         ` Bart Schaefer
2010-11-21 20:51           ` Greg Klanderman
2010-11-23 11:14         ` Peter Stephenson
2010-11-25 10:35           ` Peter Stephenson

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=20101120211528.0caf8697@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).