diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-03-30 23:27:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-03-30 23:27:14 -0700 |
commit | 0c49e3197f5713c72f2d088a4c9f382f6c019ad2 (patch) | |
tree | cae9d956d3e6f6d973a74e9eabaa60539dfe9058 /lib.c | |
parent | f4edb0505467ce4fe4ac23f1889062d0bbddb94d (diff) | |
download | txr-0c49e3197f5713c72f2d088a4c9f382f6c019ad2.tar.gz txr-0c49e3197f5713c72f2d088a4c9f382f6c019ad2.tar.bz2 txr-0c49e3197f5713c72f2d088a4c9f382f6c019ad2.zip |
New function: isecp.
* eval.c (eval_init): Register isecp intrinsic.
* lib.c (isecp): New function.
* lib.h (isecp): Declared.
* stdlib/compiler.tl (lambda-apply-transform,
dump-compiled-objects): Use isecp instead of isec, since the
actual intersection of symbols isn't needed, only whether it
exists.
* txr.1: Documented.
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -12186,6 +12186,38 @@ val isec(val seq1, val seq2, val testfun, val keyfun) return make_like(out, seq1); } +val isecp(val seq1, val seq2, val testfun, val keyfun) +{ + val self = lit("isecp"); + val out = nil; + seq_iter_t si1, si2; + val el1; + + testfun = default_arg(testfun, equal_f); + keyfun = default_arg(keyfun, identity_f); + + seq_iter_init(self, &si1, seq1); + seq_iter_init_with_rewind(self, &si2, seq2); + + while (seq_get(&si1, &el1)) { + val el1_key = funcall1(keyfun, el1); + val el2; + + seq_iter_rewind(&si2, self); + + while (seq_get(&si2, &el2)) { + val el2_key = funcall1(keyfun, el2); + + if (funcall2(testfun, el1_key, el2_key)) { + out = t; + break; + } + } + } + + return out; +} + val uni(val seq1, val seq2, val testfun, val keyfun) { val self = lit("uni"); |