summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-23 12:46:05 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-23 12:46:05 -0800
commitf43255b08af93a0ef6ce855c74a02c001cf7d8db (patch)
tree9f733895e144ad9b72f978f05cdd9a8e62e85a69 /lib.c
parentc11346723fc9142c9199591f21ce1b4e1447b741 (diff)
downloadtxr-f43255b08af93a0ef6ce855c74a02c001cf7d8db.tar.gz
txr-f43255b08af93a0ef6ce855c74a02c001cf7d8db.tar.bz2
txr-f43255b08af93a0ef6ce855c74a02c001cf7d8db.zip
* lib.c (memql): New function.
(some_satisfy): Return the first non-nil result, rather than t. (all_satisfy): Return the value of the last item, if all items are processed. * lib.h (memql): Declared. * txr.1: Documented memq, memql, memqual, tree-find, some, all, none, eq, eql and equal.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib.c b/lib.c
index eb4d2ef3..7240869b 100644
--- a/lib.c
+++ b/lib.c
@@ -411,6 +411,13 @@ val memq(val obj, val list)
return list;
}
+val memql(val obj, val list)
+{
+ while (list && !eql(car(list), obj))
+ list = cdr(list);
+ return list;
+}
+
val memqual(val obj, val list)
{
while (list && !equal(car(list), obj))
@@ -434,8 +441,9 @@ val some_satisfy(val list, val pred, val key)
key = identity_f;
for (; list; list = cdr(list)) {
- if (funcall1(pred, funcall1(key, car(list))))
- return t;
+ val item;
+ if ((item = funcall1(pred, funcall1(key, car(list)))) != nil)
+ return item;
}
return nil;
@@ -443,15 +451,17 @@ val some_satisfy(val list, val pred, val key)
val all_satisfy(val list, val pred, val key)
{
+ val item = t;
+
if (!key)
key = identity_f;
for (; list; list = cdr(list)) {
- if (!funcall1(pred, funcall1(key, car(list))))
+ if ((item = funcall1(pred, funcall1(key, car(list)))) == nil)
return nil;
}
- return t;
+ return item;
}
val none_satisfy(val list, val pred, val key)