summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-25 20:25:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-25 20:25:51 -0700
commitd5e7ea92ffcde75c4401e009c74d63ee70ba9ff2 (patch)
tree22044684ec1b7869af03ffbf8cf639feff91b874
parentb30ef1a6cb0892c142cd8ccad671e1ad2dae903a (diff)
downloadtxr-d5e7ea92ffcde75c4401e009c74d63ee70ba9ff2.tar.gz
txr-d5e7ea92ffcde75c4401e009c74d63ee70ba9ff2.tar.bz2
txr-d5e7ea92ffcde75c4401e009c74d63ee70ba9ff2.zip
in: allow hash with keyfun and testfun.
* lib.c (in): A simple check and fallthrough lets this function process hash tables more generally in this function. * txr.1: Documented.
-rw-r--r--lib.c4
-rw-r--r--txr.131
2 files changed, 31 insertions, 4 deletions
diff --git a/lib.c b/lib.c
index 1d76aa65..40662d29 100644
--- a/lib.c
+++ b/lib.c
@@ -9709,7 +9709,9 @@ val in(val seq, val item, val testfun, val keyfun)
default:
switch (si.kind) {
case SEQ_HASHLIKE:
- return tnil(gethash_e(self, si.obj, item));
+ if (null_or_missing_p(testfun) && null_or_missing_p(keyfun))
+ return tnil(gethash_e(self, si.obj, item));
+ /* fallthrough */
case SEQ_LISTLIKE:
case SEQ_VECLIKE:
{
diff --git a/txr.1 b/txr.1
index 5164cb85..324ad7d3 100644
--- a/txr.1
+++ b/txr.1
@@ -29748,11 +29748,36 @@ to produce the comparison keys. Without this
argument, the elements themselves are taken
as the comparison keys.
-If the object being searched is a hash, then the
+If the object being searched is a hash, then if neither of the arguments
.meta keyfun
-and
+nor
+.meta testfun
+is specified,
+.code in
+performs a hash lookup for
+.codn key ,
+returning
+.code t
+if the key is found,
+.code nil
+otherwise.
+If either of
+.meta keyfun
+or
.meta testfun
-arguments are ignored.
+is specified, then
+.code in
+performs an exhaustive search of the hash table, as if it were
+a sequence of
+.code cons
+cells whose
+.code car
+fields are keys, and whose
+.code cdr
+keys are values. Thus to search by key, the
+.code car
+function must be specified as
+.metn keyfun .
The
.code in