From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@math.gatech.edu
Subject: PATCH: 3.1.5 + associative arrays: fix to keys, values
Date: Thu, 17 Dec 1998 05:40:42 -0800 [thread overview]
Message-ID: <981217054042.ZM21030@candle.brasslantern.com> (raw)
In-Reply-To: <9812171017.AA27233@ibmth.df.unipi.it>
On Dec 17, 11:17am, Peter Stephenson wrote:
} Subject: Re: PATCH: 3.1.5 + associative arrays: keys, values, and pattern
}
} "Bart Schaefer" wrote:
} > The appended patch improves the implementation of the (kv) parameter flags
} > and their interaction with the (iIrR) subscripting flags.
}
} I finally had a look at these and a couple seem to be giving problems.
}
} For the tests,
}
} % typeset -A assoc
} % assoc=(one eins two zwei three drei four vier five funf)
} % print ${(k)assoc[four]}
} 0
} % print ${assoc[(r)v*]}
} eins
Fortunately these weren't too hard to fix. (I knew SCANPM_WANTINDEX was
there for something.)
} The remaining cases as far as I've tested seem fine. There is of
} course the point that the ordering is random (the `first' match of
} something could be any of them), but that's a feature of associative
} arrays which just needs to be made clear in the docs.
I hope I did so ...
}The syntax seems as good as anything I can think of.
OK.
(I did go to bed early. Then I got up early. Bleah.)
Index: Src/params.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/params.c,v
retrieving revision 1.17
diff -u -r1.17 params.c
--- params.c 1998/12/16 18:00:57 1.17
+++ params.c 1998/12/17 13:11:48
@@ -762,6 +762,8 @@
if (ind) {
v->isarr |= SCANPM_WANTKEYS;
v->isarr &= ~SCANPM_WANTVALS;
+ } else if (rev) {
+ v->isarr |= SCANPM_WANTVALS;
}
if (!down)
v->isarr &= ~SCANPM_MATCHMANY;
@@ -795,8 +797,9 @@
v->pm = createparam(s, PM_SCALAR|PM_UNSET);
paramtab = tht;
}
- v->isarr = 0;
+ v->isarr = (*inv ? SCANPM_WANTINDEX : 0);
v->a = 0;
+ *inv = 0; /* We've already obtained the "index" (key) */
*w = v->b = -1;
r = isset(KSHARRAYS) ? 1 : 0;
} else
@@ -986,9 +989,11 @@
}
if (a > 0 && (isset(KSHARRAYS) || (v->pm->flags & PM_HASHED)))
a--;
- v->inv = 1;
- v->isarr = 0;
- v->a = v->b = a;
+ if (v->isarr != SCANPM_WANTINDEX) {
+ v->inv = 1;
+ v->isarr = 0;
+ v->a = v->b = a;
+ }
if (*s == ',') {
zerr("invalid subscript", NULL, 0);
while (*s != ']' && *s != Outbrack)
Index: Src/subst.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/subst.c,v
retrieving revision 1.7
diff -u -r1.7 subst.c
--- subst.c 1998/12/15 06:58:15 1.7
+++ subst.c 1998/12/17 13:27:35
@@ -1009,7 +1009,11 @@
if ((isarr = v->isarr)) {
/* No way to get here with v->inv != 0, so getvaluearr() *
* is called by getarrvalue(); needn't test PM_HASHED. */
- aval = getarrvalue(v);
+ if (v->isarr == SCANPM_WANTINDEX) {
+ isarr = v->isarr = 0;
+ val = dupstring(v->pm->nam);
+ } else
+ aval = getarrvalue(v);
} else {
if (v->pm->flags & PM_ARRAY) {
int tmplen = arrlen(v->pm->gets.afn(v->pm));
Index: Src/zsh.h
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/zsh.h,v
retrieving revision 1.11
diff -u -r1.11 zsh.h
--- zsh.h 1998/12/15 20:14:15 1.11
+++ zsh.h 1998/12/17 13:14:04
@@ -915,7 +915,7 @@
/* Flags for extracting elements of arrays and associative arrays */
#define SCANPM_WANTVALS (1<<0)
#define SCANPM_WANTKEYS (1<<1)
-#define SCANPM_WANTINDEX (1<<2) /* Presently unused */
+#define SCANPM_WANTINDEX (1<<2)
#define SCANPM_MATCHKEY (1<<3)
#define SCANPM_MATCHVAL (1<<4)
#define SCANPM_MATCHMANY (1<<5)
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
next prev parent reply other threads:[~1998-12-17 13:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-12-13 23:33 PATCH: 3.1.5 + associative arrays: keys, values, and pattern subscripts Bart Schaefer
1998-12-14 7:35 ` Bart Schaefer
1998-12-17 10:17 ` Peter Stephenson
1998-12-17 13:40 ` Bart Schaefer [this message]
1998-12-17 16:01 ` PATCH: 3.1.5 + associative arrays: fix to keys, values 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=981217054042.ZM21030@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).