summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-07-29 22:01:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-07-29 22:01:51 -0700
commit537155e326be00e079a6aadb6a894fef733a39a0 (patch)
tree58b22b512543c5477d178d7ff4b0b061b23c367f /lib.c
parent187685ec560594fd5e1b26b76c6fea4ec92cc652 (diff)
downloadtxr-537155e326be00e079a6aadb6a894fef733a39a0.tar.gz
txr-537155e326be00e079a6aadb6a894fef733a39a0.tar.bz2
txr-537155e326be00e079a6aadb6a894fef733a39a0.zip
* eval.c (eval_init): Register uniq function.
* lib.c (uniq): New function. * lib.h (uniq): Declared. * txr.1: Documented uniq.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index afb134b8..e0e98782 100644
--- a/lib.c
+++ b/lib.c
@@ -5314,6 +5314,39 @@ val multi_sort(val lists, val funcs, val key_funcs)
return mapcarv(list_f, tuples);
}
+val uniq(val seq)
+{
+ val hash = make_hash(nil, nil, t);
+ list_collect_decl (out, ptail);
+
+ if (vectorp(seq) || stringp(seq)) {
+ cnum i, len;
+
+ for (i = 0, len = c_num(length(seq)); i < len; i++) {
+ val new_p;
+ val v = ref(seq, num_fast(i));
+
+ (void) gethash_c(hash, v, mkcloc(new_p));
+
+ if (new_p)
+ ptail = list_collect(ptail, v);
+ }
+ } else {
+ for (; seq; seq = cdr(seq)) {
+ val new_p;
+ val v = car(seq);
+
+ (void) gethash_c(hash, v, mkcloc(new_p));
+
+ if (new_p)
+ ptail = list_collect(ptail, v);
+ }
+ }
+
+ return make_like(out, seq);
+}
+
+
val find(val item, val list, val testfun, val keyfun)
{
testfun = default_arg(testfun, equal_f);