diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-01-24 07:30:00 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-01-24 07:30:00 -0800 |
commit | 24f50b052eb8f8fe3a37d60d0a9e6daebab7f84a (patch) | |
tree | 69b708e12a8cff8a2c100e0b8e76d84a93fa7c80 /lib.c | |
parent | 21ecebc20e45132bd1c78fd5392b5f6523e4c9e6 (diff) | |
download | txr-24f50b052eb8f8fe3a37d60d0a9e6daebab7f84a.tar.gz txr-24f50b052eb8f8fe3a37d60d0a9e6daebab7f84a.tar.bz2 txr-24f50b052eb8f8fe3a37d60d0a9e6daebab7f84a.zip |
* hash.c (hash_update): New function.
* hash.h (hash_update): Declared.
* lib.c (update): New function.
* lib.h (update): Declared.
* eval.c (eval_init): Register hash_update and update as intrinsics.
* txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -4819,6 +4819,43 @@ val replace(val seq, val items, val from, val to) } } +val update(val seq, val fun) +{ + switch (type(seq)) { + case NIL: + break; + case CONS: + case LCONS: + { + val iter = seq; + + while (consp(iter)) { + rplaca(iter, funcall1(fun, car(iter))); + iter = cdr(iter); + } + } + break; + case LIT: + case STR: + case VEC: + { + val len = length(seq); + val i; + for (i = zero; lt(i, len); i = plus(i, one)) + refset(seq, i, funcall1(fun, ref(seq, i))); + } + break; + case COBJ: + if (hashp(seq)) + return hash_update(seq, fun); + /* fallthrough */ + default: + type_mismatch(lit("replace: ~s is not a sequence"), cons, nao); + } + + return seq; +} + val env(void) { if (env_list) { |