summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-26 06:56:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-26 06:56:10 -0700
commit3dbaecd359c584e1bcf650cdf53fb35253599e15 (patch)
treecdabf8284e140a72cd19e447bfab7ec7bde94f85 /lib.c
parent5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7 (diff)
downloadtxr-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.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index 61390692..422396f0 100644
--- a/lib.c
+++ b/lib.c
@@ -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)