diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-09 06:25:11 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-09 06:25:11 -0800 |
commit | 3fb108272f762a4e3afa3f2f925db03b3128c272 (patch) | |
tree | bcc2195735027e7133ee91249d349dc9be15584c /lib.c | |
parent | 25bf01699c2af7f8007404d5a62aeb1d64aee7b0 (diff) | |
download | txr-3fb108272f762a4e3afa3f2f925db03b3128c272.tar.gz txr-3fb108272f762a4e3afa3f2f925db03b3128c272.tar.bz2 txr-3fb108272f762a4e3afa3f2f925db03b3128c272.zip |
New function: cons-find.
* eval.c (cons_find): Static function removed; a new one is
implemented in lib.c.
(eval_init): Register cons-find intrinsic.
* lib.c (cons_find_rec): New static function.
(cons_find): New function.
* lib.h (cons_find): Declared.
* tests/012/cons.tl: New file.
* txr.1: Documented cons-find together with tree-find.
Document that tree-find's test-fun argument is optional,
defaulting to equal.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -3471,6 +3471,23 @@ val tree_find(val obj, val tree, val testfun) return nil; } +static val cons_find_rec(val obj, val tree, val testfun) +{ + uses_or2; + if (funcall2(testfun, obj, tree)) + return t; + else if (consp(tree)) + return or2(cons_find_rec(obj, us_car(tree), testfun), + cons_find_rec(obj, us_cdr(tree), testfun)); + else + return nil; +} + +val cons_find(val obj, val tree, val testfun) +{ + return cons_find_rec(obj, tree, default_arg(testfun, equal_f)); +} + val countqual(val obj, val seq) { val self = lit("countqual"); |