diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-06-26 06:56:10 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-06-26 06:56:10 -0700 |
commit | 3dbaecd359c584e1bcf650cdf53fb35253599e15 (patch) | |
tree | cdabf8284e140a72cd19e447bfab7ec7bde94f85 /lib.c | |
parent | 5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7 (diff) | |
download | txr-3dbaecd359c584e1bcf650cdf53fb35253599e15.tar.gz txr-3dbaecd359c584e1bcf650cdf53fb35253599e15.tar.bz2 txr-3dbaecd359c584e1bcf650cdf53fb35253599e15.zip |
* eval.c (mapcarv): Use mapcar_listout, so list_of_lists can be
a non-list sequence.
(eval_init): Register transpose and zip as intrinsics.
* lib.c (curry_12_1_v): New static function.
(transpose, mapcar_listout): New functions.
(mapcar): Redefined in terms of mapcar_listout.
* lib.h (transpose, mapcar_listout): Declared.
* txr.1: Documented transpose and zip.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 35 |
1 files changed, 32 insertions, 3 deletions
@@ -3894,6 +3894,11 @@ val curry_12_1(val fun2, val arg2) return func_f1(cons(fun2, arg2), do_curry_12_1); } +static val curry_12_1_v(val fun2, val arg2) +{ + return func_f0v(cons(fun2, arg2), do_curry_12_1); +} + static val do_curry_123_3(val fcons, val arg3) { return funcall3(car(fcons), car(cdr(fcons)), cdr(cdr(fcons)), arg3); @@ -3944,6 +3949,26 @@ val curry_1234_34(val fun4, val arg1, val arg2) return func_f2(cons(fun4, cons(arg1, arg2)), do_curry_1234_34); } +val transpose(val list) +{ + val func = list_f; + + switch (type(car(list))) { + case STR: + case LSTR: + case LIT: + func = curry_12_1_v(func_n2(cat_str), nil); + break; + case VEC: + func = func_n0v(vector_list); + break; + default: + break; + } + + return make_like(mapcarv(func, list), list); +} + static val do_chain(val fun1_list, val args) { val arg = nil; @@ -4821,17 +4846,21 @@ val copy_alist(val list) return mapcar(func_n1(copy_cons), list); } -val mapcar(val fun, val list) +val mapcar_listout(val fun, val list) { list_collect_decl (out, iter); - val list_orig = list; list = nullify(list); for (; list; list = cdr(list)) iter = list_collect(iter, funcall1(fun, car(list))); - return make_like(out, list_orig); + return out; +} + +val mapcar(val fun, val list) +{ + return make_like(mapcar_listout(fun, list), list); } val mapcon(val fun, val list) |