diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-12-23 09:13:13 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-12-23 09:13:13 -0800 |
commit | e68f3828d79d16d2afc929c83d499e8e2e0dd38a (patch) | |
tree | b66ed1583320df34484fdb0c474d953ef48570a7 /lib.c | |
parent | ebb980b2ee0414ca4369049f489ad8e6ce1ad148 (diff) | |
download | txr-e68f3828d79d16d2afc929c83d499e8e2e0dd38a.tar.gz txr-e68f3828d79d16d2afc929c83d499e8e2e0dd38a.tar.bz2 txr-e68f3828d79d16d2afc929c83d499e8e2e0dd38a.zip |
* eval.c (eval_init): Registered intrinsic function unique.
* lib.c (unique): New function.
(uniq): Becomes wrapper around unique.
* lib.h (unique): Declared.
* txr.1: Documented unique, and equivalence between uniq and unique.
* tl.vim, txr.vim: Regenerated.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -5787,9 +5787,11 @@ val sort_group(val seq, val keyfun, val lessfun) return partition_by(kf, sorted); } -val uniq(val seq) +val unique(val seq, val keyfun, val hashargs) { - val hash = make_hash(nil, nil, t); + val hash = hashv(default_bool_arg(hashargs)); + val kf = default_arg(keyfun, identity_f); + list_collect_decl (out, ptail); if (vectorp(seq) || stringp(seq)) { @@ -5799,7 +5801,7 @@ val uniq(val seq) val new_p; val v = ref(seq, num_fast(i)); - (void) gethash_c(hash, v, mkcloc(new_p)); + (void) gethash_c(hash, funcall1(kf, v), mkcloc(new_p)); if (new_p) ptail = list_collect(ptail, v); @@ -5809,7 +5811,7 @@ val uniq(val seq) val new_p; val v = car(seq); - (void) gethash_c(hash, v, mkcloc(new_p)); + (void) gethash_c(hash, funcall1(kf, v), mkcloc(new_p)); if (new_p) ptail = list_collect(ptail, v); @@ -5819,6 +5821,11 @@ val uniq(val seq) return make_like(out, seq); } +val uniq(val seq) +{ + return unique(seq, identity_f, cons(equal_based_k, nil)); +} + val find(val item, val list, val testfun, val keyfun) { testfun = default_arg(testfun, equal_f); |