zsh-workers
 help / color / mirror / code / Atom feed
* unsetting array elements
@ 1998-11-19 15:08 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 1998-11-19 15:08 UTC (permalink / raw)
  To: Zsh hackers list

I've just been looking into the unset problem, and it looks like ksh
88 (this one's called Version 11/16/88d SBCS) is doing something a
little bit dodgy.

> set -A var foo bar
> unset var[0]                        # works this time
> echo ${var[*]}
bar
> set -A var foo bar
> touch var0        
> unset var[0]                        # this time var[0] -> var0
> echo ${var[*]}
foo bar

So in that version unset behaved as a normal command, just relying on
the fact that the thing was left alone if it didn't match a file.
Unsetting elements doesn't work at all yet in zsh.  It's harder to
implement because of the nomatch and nullglob behaviours.  Of course,
you could get it to work in quotes and say so in the manual.  Or you
could turn off globbing for unset, which could be implemented in the
same way that typeset knows when to expand ~'s after an `=' ---
probably workable since you'd have to be a complete weirdo to rely on
globbing in this case.

By the way, ksh also ignores unset parts of arrays completely, even
with "${var[@]}".  Zsh would emit extra empty strings for the
unset part, and this requires some major surgery to change since a
null byte marks the end of the array.  In associative arrays
you can remove the element completely and it's not a problem.

I'd thought of making a bolder project both to make unset special and
to have typeset etc. get variable-type arguments instead of just
strings, which would make things like `local var=(foo bar)' work; the
current behaviour tends to surprise people.  But that would require
spotting the command very early on during parsing which would have all
sorts of side effects of two types: first, quoting bits of the command
name would turn this off; second, it would have to decide at parse
time whether there was a function instead, or whether the command was
disabled, and things like 'builtin typeset' would have to be
special-cased in the parser.  Then you'd probably have to keep the
existing typeset code for cases where the command was called without
the special parsing activated.  So it looks rather unpleasant.

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-11-19 15:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-19 15:08 unsetting array elements Peter Stephenson

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