summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-16 21:43:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-16 21:43:51 -0700
commit8bb336298d0bf4e165fa03f7f2a219ddad6e466f (patch)
tree2b102c6c3fd927a4589b4b1cf75099c9cdc97384 /lib.c
parent5e765926b07b544f9dd4860af5f0e669432434ea (diff)
downloadtxr-8bb336298d0bf4e165fa03f7f2a219ddad6e466f.tar.gz
txr-8bb336298d0bf4e165fa03f7f2a219ddad6e466f.tar.bz2
txr-8bb336298d0bf4e165fa03f7f2a219ddad6e466f.zip
* eval.c (eval_init): New intrinsic functions
chain, andf, orf, iff. * lib.c (chainv): New function. (do_and, do_or): Generalized to handle functions of any arguments via apply. (andf, orf): Turn do_and and do_or into variadic function instead of a monadic function. (do_iff): New static function. (andv, orv, iff): New functions. * lib.h (chainv, andv, orv, iff): New functions declared. * txr.1: Doc stubs created. * txr.vim: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/lib.c b/lib.c
index cc5e7ed3..9d3c1ccb 100644
--- a/lib.c
+++ b/lib.c
@@ -2842,10 +2842,15 @@ val chain(val first_fun, ...)
return func_f1(out, do_chain);
}
-static val do_and(val fun1_list, val arg)
+val chainv(val funlist)
+{
+ return func_f1(funlist, do_chain);
+}
+
+static val do_and(val fun1_list, val args)
{
for (; fun1_list; fun1_list = cdr(fun1_list))
- if (nullp(funcall1(car(fun1_list), arg)))
+ if (nullp(apply(car(fun1_list), args, nil)))
return nil;
return t;
@@ -2867,7 +2872,12 @@ val andf(val first_fun, ...)
va_end (vl);
}
- return func_f1(out, do_and);
+ return func_f0v(out, do_and);
+}
+
+val andv(val funlist)
+{
+ return func_f0v(funlist, do_and);
}
static val do_swap_12_21(val fun, val left, val right)
@@ -2880,10 +2890,10 @@ val swap_12_21(val fun)
return func_f2(fun, do_swap_12_21);
}
-static val do_or(val fun1_list, val arg)
+static val do_or(val fun1_list, val args)
{
for (; fun1_list; fun1_list = cdr(fun1_list))
- if (funcall1(car(fun1_list), arg))
+ if (apply(car(fun1_list), args, nil))
return t;
return nil;
@@ -2905,7 +2915,27 @@ val orf(val first_fun, ...)
va_end (vl);
}
- return func_f1(out, do_or);
+ return func_f0v(out, do_or);
+}
+
+val orv(val funlist)
+{
+ return func_f0v(funlist, do_or);
+}
+
+static val do_iff(val env, val args)
+{
+ cons_bind (condfun, choices, env);
+ cons_bind (thenfun, elsefun, choices);
+
+ return if3(apply(condfun, args, nil),
+ apply(thenfun, args, nil),
+ if2(elsefun, apply(elsefun, args, nil)));
+}
+
+val iff(val condfun, val elsefun, val thenfun)
+{
+ return func_f0v(cons(condfun, cons(elsefun, thenfun)), do_iff);
}
val vector(val length)