summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-10-22 20:02:45 -0400
committerKaz Kylheku <kaz@kylheku.com>2011-10-22 20:02:45 -0400
commitc6de88f486896be891e73009dbe2ea0411bf89e1 (patch)
tree78a4401ba4035004bf7bf1575f729dacd16b81a7 /lib.c
parent6ddb4b8f329b14e6133f29573cfeb88d1ee30846 (diff)
downloadtxr-c6de88f486896be891e73009dbe2ea0411bf89e1.tar.gz
txr-c6de88f486896be891e73009dbe2ea0411bf89e1.tar.bz2
txr-c6de88f486896be891e73009dbe2ea0411bf89e1.zip
Task #11474
* filter.c (filter_equal): Takes two filters instead of one. (lfilt_k, rfilt_k): New keyword variables. (filter_init): New keyword variables initialized. * filter.h (filter_equal): Declaration updated. (lfilt_k, rfilt_k): Declared. * lib.c (funcall4): New function. (do_curry_1234_34): New static function. (curry_1234_34): New function. (do_swap_12_21): New static function. (swap_12_21): New function. * lib.h (funcall4, curry_1234_34, swap_12_21): Declared. * match.c (dest_bind): Swap use the function argument swapping combinator when calling tree find such that the value being searched is on the left and pattern material is on the right. (v_bind): Implemented :lfilt and :rfilt. * txr.1: Documented :lfilt and :rfilt.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 98a9a056..064cb8ee 100644
--- a/lib.c
+++ b/lib.c
@@ -1541,6 +1541,22 @@ val funcall3(val fun, val arg1, val arg2, val arg3)
}
}
+val funcall4(val fun, val arg1, val arg2, val arg3, val arg4)
+{
+ type_check(fun, FUN);
+
+ switch (fun->f.functype) {
+ case F4:
+ return fun->f.f.f4(fun->f.env, arg1, arg2, arg3, arg4);
+ case N4:
+ return fun->f.f.n4(arg1, arg2, arg3, arg4);
+ default:
+ uw_throwf(error_s, lit("funcall4: wrong number of arguments"));
+ }
+}
+
+
+
val reduce_left(val fun, val list, val init, val key)
{
@@ -1593,6 +1609,16 @@ val curry_123_23(val fun3, val arg1)
return func_f2(cons(fun3, arg1), do_curry_123_23);
}
+static val do_curry_1234_34(val fcons, val arg3, val arg4)
+{
+ return funcall4(car(fcons), car(cdr(fcons)), cdr(cdr(fcons)), arg3, arg4);
+}
+
+val curry_1234_34(val fun4, val arg1, val arg2)
+{
+ return func_f2(cons(fun4, cons(arg1, arg2)), do_curry_1234_34);
+}
+
static val do_chain(val fun1_list, val arg)
{
for (; fun1_list; fun1_list = cdr(fun1_list))
@@ -1648,6 +1674,16 @@ val andf(val first_fun, ...)
return func_f1(out, do_and);
}
+static val do_swap_12_21(val fun, val left, val right)
+{
+ return funcall2(fun, right, left);
+}
+
+val swap_12_21(val fun)
+{
+ return func_f2(fun, do_swap_12_21);
+}
+
val vector(val alloc)
{
cnum alloc_plus = c_num(alloc) + 2;