zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@math.gatech.edu
Subject: PATCH: 3.1.5-pws-4: minor setaparam() fixup for assoc. arrays
Date: Tue, 12 Jan 1999 09:55:52 -0800	[thread overview]
Message-ID: <990112095552.ZM12994@candle.brasslantern.com> (raw)

Consider the following:

zsh% typeset -A assoc
zsh% : ${(A)assoc[key]::=x y z}

This actually "worked" fine and set $assoc[key] to be the array (x y z).
However, none of the other substitution code is ready to have associative
arrays contain anything but scalars.  The following patch turns the above
fragment into an error case, and improves the error message in the case of

zsh% : ${(AA)=assoc[key]::=x y z}

I had mentioned before that perhaps that case should be changed to not
produce an error, but upon reflection I think it's better as it is.  To
assign to a single field of an associative array using the ${...:=...}
syntax, simply write

zsh% : ${assoc[key]::=value}

which already works with the obvious meaning (no change in this patch).

Index: Src/params.c
===================================================================
--- params.c	1999/01/11 02:19:45	1.20
+++ params.c	1999/01/12 16:51:55
@@ -1534,6 +1534,12 @@
 	if (!(v = getvalue(&s, 1)))
 	    createparam(t, PM_ARRAY);
 	*ss = '[';
+	if (PM_TYPE(v->pm->flags) == PM_HASHED) {
+	    zerr("attempt to set slice of associative array", NULL, 0);
+	    freearray(val);
+	    errflag = 1;
+	    return NULL;
+	}
 	v = NULL;
     } else {
 	if (!(v = getvalue(&s, 1)))
@@ -1571,7 +1577,7 @@
     }
     if (strchr(s, '[')) {
 	freearray(val);
-	zerr("attempt to set slice of associative array", NULL, 0);
+	zerr("nested associative arrays not yet supported", NULL, 0);
 	errflag = 1;
 	return NULL;
     } else {

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


                 reply	other threads:[~1999-01-12 17:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=990112095552.ZM12994@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@math.gatech.edu \
    /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).