zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@math.gatech.edu
Subject: Re: PATCH: 3.1.5 + associative arrays: keys, values, and pattern subscripts
Date: Sun, 13 Dec 1998 23:35:28 -0800	[thread overview]
Message-ID: <981213233528.ZM19211@candle.brasslantern.com> (raw)
In-Reply-To: <981213153332.ZM15459@candle.brasslantern.com>

On Dec 13,  3:33pm, Bart Schaefer wrote:
} Subject: PATCH: 3.1.5 + associative arrays: keys, values, and pattern subs
}
} Implementation notes:
} 
} I overloaded the `isarr' field of struct value to hold flag bits for all
} this, and backed out the previous hack of overloading both the `a' and `b'
} fields.  The difference between $array[*] and $array[@] is still stashed
} in the sign bit, mostly to minimize the number of lines changed.  I don't
} believe this has broken anything, but keep your eyes open.

Of course I did break something, in the course of getting [(i)pat] to NOT
return all the values in the array.

I had also messed up these cases:

                        Associative Array        Ordinary Array
                        -----------------        --------------
  $param                All values in param      All values in param
                        or empty if none         or empty if none

  $param[(i)pat]        A key in param that      Index of first value that
                        matches pattern pat      matches pattern pat

  $param[(I)pat]        All keys in param that   Index of last value that
                        match pattern pat        matches pattern pat

They worked correctly if an explicit ${(k)...} or ${(v)...} was given, but
not in the default cases.

The following patch puts things right, and must be applied *after* the
previous patch (zsh-workers/4763).

Index: Src/params.c
===================================================================
--- params.c	1998/12/14 02:17:35	1.13
+++ params.c	1998/12/14 07:27:11
@@ -751,8 +751,15 @@
 	*inv = (ind || !(v->isarr & SCANPM_WANTVALS));
     else if (v->isarr & SCANPM_WANTVALS)
 	*inv = 0;
-    else
+    else {
+	if (ind) {
+	    v->isarr |= SCANPM_WANTKEYS;
+	    v->isarr &= ~SCANPM_WANTVALS;
+	}
+	if (!down)
+	    v->isarr &= ~SCANPM_MATCHMANY;
 	*inv = ind;
+    }
 
     for (t=s, i=0; *t && ((*t != ']' && *t != Outbrack && *t != ',') || i); t++)
 	if (*t == '[' || *t == Inbrack)
@@ -1078,6 +1085,12 @@
 	if (PM_TYPE(pm->flags) & (PM_ARRAY|PM_HASHED)) {
 	    /* Overload v->isarr as the flag bits for hashed arrays. */
 	    v->isarr = flags | (isvarat ? SCANPM_ISVAR_AT : 0);
+	    /* If no flags were passed, we need something to represent *
+	     * `true' yet differ from an explicit WANTVALS.  This is a *
+	     * bit of a hack, but makes some sense:  When no subscript *
+	     * is provided, all values are substituted.                */
+	    if (!v->isarr)
+		v->isarr = SCANPM_MATCHMANY;
 	}
 	v->pm = pm;
 	v->inv = 0;


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


  reply	other threads:[~1998-12-14  7:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-13 23:33 Bart Schaefer
1998-12-14  7:35 ` Bart Schaefer [this message]
1998-12-17 10:17 ` Peter Stephenson
1998-12-17 13:40   ` PATCH: 3.1.5 + associative arrays: fix to keys, values Bart Schaefer
1998-12-17 16:01     ` Peter Stephenson
1998-12-17 16:52       ` Bart Schaefer
1998-12-17 17:24         ` Bart Schaefer
1998-12-18  2:44           ` Geoff Wing

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=981213233528.ZM19211@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).