zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: "ZSH workers mailing list" <zsh-workers@sunsite.auc.dk>
Subject: Re: Possible bug with ${(A)foo=} and ${(AA)foo=}
Date: Wed, 23 Jun 1999 12:02:56 +0200	[thread overview]
Message-ID: <9906231002.AA17151@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Tue, 22 Jun 1999 17:36:28 DFT." <990622173628.ZM30363@candle.brasslantern.com>

"Bart Schaefer" wrote:
> On Jun 22,  8:13pm, Andrej Borsenkow wrote:
> } Subject: Possible bug with ${(A)foo=} and ${(AA)foo=}
> }
> } While playing with something else I discovered, that it is impossible to
> } create empty array with this form and it is impossible to create hash in
> } this way without error message:
> 
> The first problem is what causes the second, though creating an empty AA
> this way would create an empty hash table (normally the hash table is not
> created until the AA has at least one value).

Without fixing the general array-splitting problem, which is difficult, I
don't see there's any problem deciding what to do in the case of an
associative array, since the intention in such a case can only be to create
an empty one because there is no key/value pair, even with ${(AA)foo=''}
since wordsplitting can't change that fact.  So until somebody gets around
to doing array splitting in this case properly, I suggest we just assume it
should create an empty associative array.  The other problems are far less
pressing because if the associative array already exists there are always
other ways of setting it, which in practice aret the ones we always use.

I was thinking about `typeset -g foo' to stop foo becoming local if it
doesn't exist, but there is always the problem with what to do when foo
already exists but has been unset.  The easiest thing is always to use that
value at the level at which was set.  This means, for example,

fn2() { typset -g foo; }
fn1() { typeset foo; unset foo; fn2(); foo=bar; }

that foo remains throughout local to fn1.  I think this version could be
implemented quite easily.  Any other version is going to be messy.

--- Src/subst.c.aa	Tue Jun 15 17:06:48 1999
+++ Src/subst.c	Wed Jun 23 11:51:00 1999
@@ -1328,10 +1328,15 @@
 			else
 			    t = aval;
 		    } else if (!isarr) {
-			arr[0] = val;
-			arr[1] = NULL;
+			if (!*val && arrasg > 1) {
+			    arr[0] = NULL;
+			    l = 0;
+			} else {
+			    arr[0] = val;
+			    arr[1] = NULL;
+			    l = 1;
+			}
 			t = aval = arr;
-			l = 1;
 		    } else
 			l = arrlen(aval), t = aval;
 		    p = a = zalloc(sizeof(char *) * (l + 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


  reply	other threads:[~1999-06-23 10:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-22 16:13 Andrej Borsenkow
1999-06-22 17:36 ` Bart Schaefer
1999-06-23 10:02   ` Peter Stephenson [this message]
1999-06-24 15:36     ` PATCH: " Bart Schaefer

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=9906231002.AA17151@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).