zsh-workers
 help / color / mirror / code / Atom feed
* Re:  PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
@ 1999-02-12  9:48 Sven Wischnowsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 1999-02-12  9:48 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> 
> > The same for `$a[*]' and `$a'.
> 
> That's right, surely?  Quoted variables only expand to nothing if the
> @ is present.

Yep, I wanted to write `... as for...'. Interesting, gives a
completely different sentence.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
  1999-02-12 15:45     ` Peter Stephenson
@ 1999-02-12 17:33       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 1999-02-12 17:33 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

On Feb 12,  4:45pm, Peter Stephenson wrote:
} Subject: Re: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
}
} Try it in ksh, and remember you need "${f[@]}"

OK, I concur.  3.0.5 is broken in the same way, then.

However, with your patch, I get this:

zagzig% foo() { echo $# "$@" }
zagzig% foo "$unset[@]"
zsh: segmentation fault (core dumped)  Src/zsh -f


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
  1999-02-12 15:43   ` Bart Schaefer
@ 1999-02-12 15:45     ` Peter Stephenson
  1999-02-12 17:33       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 1999-02-12 15:45 UTC (permalink / raw)
  To: zsh-workers

> } Sven Wischnowsky wrote:
> } >   % foo() { echo $# }
> } >   % unset a
> } >   % foo $a[@]
> } >   0                    # fine
> } >   % foo "$a[@]"
> } >   1                    # oops
> 
> That's not an "oops".  That's the way it's supposed to work.  Try the
> equivalent code in bash.

Bash doesn't even have arrays, apart from "$@", of course.  Try it in
ksh, and remember you need "${f[@]}" because the bracing rules are
more strict, and you'll find it elides the whole thing as with the
patch.

Taking a @ subscript was never a well-defined thing to do on a scalar,
whether or not it happens to be so with a zsh extension; its essential
purpose is to provide word splitting for arrays in strings, so zero
elements gives zero words.  (And if it leaves a null argument on the
line for an empty scalar, I would argue that's inconsistently
implemented.)

> I don't think we want this patch.

It seems pretty clear to me the shell is just plain broken without it.

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
  1999-02-12  9:28 ` PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset Peter Stephenson
@ 1999-02-12 15:43   ` Bart Schaefer
  1999-02-12 15:45     ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 1999-02-12 15:43 UTC (permalink / raw)
  To: zsh-workers

On Feb 12, 10:28am, Peter Stephenson wrote:
} Subject: PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
}
} Sven Wischnowsky wrote:
} >   % foo() { echo $# }
} >   % unset a
} >   % foo $a[@]
} >   0                    # fine
} >   % foo "$a[@]"
} >   1                    # oops

That's not an "oops".  That's the way it's supposed to work.  Try the
equivalent code in bash.

[schaefer@zagzig zsh-3.1.5-work]$ unset f
[schaefer@zagzig zsh-3.1.5-work]$ foo() { echo $#; echo "$@"; }
[schaefer@zagzig zsh-3.1.5-work]$ foo "$f[@]"
1
[@]

c[1] ksh
$ unset f
$ foo() { echo $#; echo "$@"; }  
$ foo "$f[@]"
1
[@]

(I had to ssh to my old grad school account to get that ksh example.)

zagzig[32] ARGV0=ksh zsh
zagzig% unset f
zagzig% foo() { echo $#; echo "$@"; }
zagzig% foo "$f[@]"
1
[@]

} Note that putting `a=()' before would have been a workaround.

That's The Right Thing To Do, not a workaround.

} Quoted variables only expand to nothing if the @ is present.

On a scalar -- which is what `a' is if you've never done `a=()' -- the
string $a[@] expands to all the characters in the value of $a; it's the
same as just "$a".  The quoted-@ magic doesn't apply when slicing a
scalar.

I don't think we want this patch.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset
  1999-02-12  8:53 Tar file and Re: Bad interaction between -iprefix and -string Sven Wischnowsky
@ 1999-02-12  9:28 ` Peter Stephenson
  1999-02-12 15:43   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 1999-02-12  9:28 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
>   % foo() { echo $# }
>   % unset a
>   % foo $a[@]
>   0                    # fine
>   % foo "$a[@]"
>   1                    # oops

The code's a little murky (as in `hell is murky' --- or'ing with
something is a pretty shoddy way of making a value negative,
particularly when the SCANPM_ISVAR_AT flag is never seen again), but
the following seems to do the trick.  Note that putting `a=()' before
would have been a workaround.

> The same for `$a[*]' and `$a'.

That's right, surely?  Quoted variables only expand to nothing if the
@ is present.

--- Src/params.c.isarr	Mon Feb  1 09:52:30 1999
+++ Src/params.c	Fri Feb 12 10:14:14 1999
@@ -966,7 +966,7 @@
     if (*tbrack == Outbrack)
 	*tbrack = ']';
     if ((s[0] == '*' || s[0] == '@') && s[1] == ']') {
-	if (v->isarr && s[0] == '@')
+	if ((v->isarr || !v->pm || !*v->pm->nam) && s[0] == '@')
 	    v->isarr |= SCANPM_ISVAR_AT;
 	v->a = 0;
 	v->b = -1;

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1999-02-12 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-12  9:48 PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-02-12  8:53 Tar file and Re: Bad interaction between -iprefix and -string Sven Wischnowsky
1999-02-12  9:28 ` PATCH: zsh-3.1.5-pws-7: "$a[@]" with $a unset Peter Stephenson
1999-02-12 15:43   ` Bart Schaefer
1999-02-12 15:45     ` Peter Stephenson
1999-02-12 17:33       ` Bart Schaefer

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).