Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter



Peter Stephenson wrote:

> >   The behavior is a bit weird, though, because `${foo-bar}' uses
> >   `multsub', too. I haven't changed the call to it, yet, so the result 
> >   is that the `bar' is broken into an array -- always. This means that 
> >   `${#:-$foo}' will yield `1' for strings and the number of elements
> >   if `bar' is `$baz' where `baz' is an array. I didn't change it
> >   because I wanted to ask what it should do first, suggestions are:
> > 
> >   1) let it treat the `bar' always as a string (i.e. let it never be
> >      split into array elements); I guess this is what most people
> >      would expect (and in the manual the thing is called `word')
> 
> Since (without shwordsplit)
> 
>   % args() { print $#; }
>   % args ${foo:-foo bar}
>   1
> 
> this is the natural thing to do.

I liked this one best, too, so the patch below implements it.

> >   2) like 1), but if combined with the `A' flag, let it be treated as
> >      an array
> 
> Some extension like this is reasonable, but the obvious candidate is
> ${(w)#:-foo bar}, which is supposed to have exactly this effect on $# for a
> string.
> 
>  % foo="foo bar"
>  % print ${(w)#foo}
>  2

Right, hadn't thought of that.

Bye
 Sven

--- os/subst.c	Mon Mar 15 10:52:31 1999
+++ Src/subst.c	Tue Mar 16 12:46:13 1999
@@ -1273,7 +1273,7 @@
 	case '-':
 	    if (vunset) {
 		val = dupstring(s);
-		multsub(&val, &aval, &isarr, NULL);
+		multsub(&val, NULL, &isarr, NULL);
 		copied = 1;
 	    }
 	    break;

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author