summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--eval.c1
-rw-r--r--lib.c23
-rw-r--r--lib.h1
-rw-r--r--txr.119
5 files changed, 54 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 523d9f74..b68b18f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2014-11-06 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (eval_init): Register chand intrinsic.
+
+ * lib.c (do_chand): New static function.
+ (chandv): New function.
+
+ * lib.h (chandv): Declared.
+
+ * txr.1: Documented chand.
+
+2014-11-06 Kaz Kylheku <kaz@kylheku.com>
+
Allow then-func to be omitted in iff. Cleanup.
* eval.c (eval_init): Register iff as requiring only one arg.
diff --git a/eval.c b/eval.c
index 402d19a2..acfe8a21 100644
--- a/eval.c
+++ b/eval.c
@@ -3745,6 +3745,7 @@ void eval_init(void)
reg_fun(intern(lit("env-fbind"), user_package), func_n3(env_fbind));
reg_fun(intern(lit("env-vbind"), user_package), func_n3(env_vbind));
reg_fun(intern(lit("chain"), user_package), func_n0v(chainv));
+ reg_fun(intern(lit("chand"), user_package), func_n0v(chandv));
reg_fun(intern(lit("juxt"), user_package), func_n0v(juxtv));
reg_fun(intern(lit("andf"), user_package), func_n0v(andv));
reg_fun(intern(lit("orf"), user_package), func_n0v(orv));
diff --git a/lib.c b/lib.c
index 6abbf1f1..3c828d14 100644
--- a/lib.c
+++ b/lib.c
@@ -4498,6 +4498,29 @@ val chainv(val funlist)
return func_f0v(nullify(funlist), do_chain);
}
+static val do_chand(val fun1_list, val args)
+{
+ val arg = nil;
+
+ fun1_list = nullify(fun1_list);
+
+ if (fun1_list) {
+ arg = apply(car(fun1_list), args, nil);
+ fun1_list = cdr(fun1_list);
+ }
+
+ for (; arg && fun1_list; fun1_list = cdr(fun1_list))
+ arg = funcall1(car(fun1_list), arg);
+
+ return arg;
+}
+
+
+val chandv(val funlist)
+{
+ return func_f0v(nullify(funlist), do_chand);
+}
+
static val do_juxt(val funcs, val args)
{
return mapcar(curry_123_1(func_n3(apply), args, nil), funcs);
diff --git a/lib.h b/lib.h
index b59eb875..086967b0 100644
--- a/lib.h
+++ b/lib.h
@@ -728,6 +728,7 @@ val curry_123_23(val fun3, val arg1);
val curry_1234_34(val fun3, val arg1, val arg2);
val chain(val first_fun, ...);
val chainv(val funlist);
+val chandv(val funlist);
val juxtv(val funlist);
val andf(val first_fun, ...);
val andv(val funlist);
diff --git a/txr.1 b/txr.1
index 2ca3a0a1..98347815 100644
--- a/txr.1
+++ b/txr.1
@@ -20443,9 +20443,10 @@ and the expression
returns a function similar to
.codn (lambda (. rest) 42) .
-.coNP Function @ chain
+.coNP Functions @ chain and @ chand
.synb
.mets (chain << func *)
+.mets (chand << func *)
.syne
.desc
The
@@ -20469,6 +20470,22 @@ function. The return value of that call is then passed to the second
function, and the return value of that call is passed to the third function
and so on. The final return value is returned to the caller.
+The
+.code chand
+function is similar, except that it combines the functionality of
+.code andf
+into chaining. The difference between
+.code chain
+and
+.code chand
+is that
+.code chand
+immediately terminates and returns
+.code nil
+whenever any of the functions returns
+.codn nil ,
+without evaluating the remainder of the functions.
+
.TP* Example:
.cblk