summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-01-24 22:22:27 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-01-24 22:22:27 -0800
commit6c9893d4790f1a27c900b2d84a3532ae7c402463 (patch)
treeebe02f2214fde29154735f1ef2e9372a15772377
parentc12e24f335c4b37d9abc24f387dc1e06de1058df (diff)
downloadtxr-6c9893d4790f1a27c900b2d84a3532ae7c402463.tar.gz
txr-6c9893d4790f1a27c900b2d84a3532ae7c402463.tar.bz2
txr-6c9893d4790f1a27c900b2d84a3532ae7c402463.zip
* eval.c (callf): New static function.
(eval_init): callf registered. * txr.1: Documented callf.
-rw-r--r--ChangeLog7
-rw-r--r--eval.c8
-rw-r--r--txr.132
3 files changed, 47 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d1a6fa7e..0009d647 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-24 Kaz Kylheku <kaz@kylheku.com>
+
+ * eval.c (callf): New static function.
+ (eval_init): callf registered.
+
+ * txr.1: Documented callf.
+
2015-01-22 Kaz Kylheku <kaz@kylheku.com>
Basic implementation of constantp. Does not
diff --git a/eval.c b/eval.c
index bba8be6e..de125ea0 100644
--- a/eval.c
+++ b/eval.c
@@ -3455,6 +3455,13 @@ static val ipf(val fun)
return func_f0v(fun, do_ipf);
}
+static val callf(val func, val funlist)
+{
+ val juxt_fun = juxtv(funlist);
+ val apf_fun = apf(func);
+ return chain(juxt_fun, apf_fun, nao);
+}
+
static val prinl(val obj, val stream)
{
val ret = obj_print(obj, stream);
@@ -3902,6 +3909,7 @@ void eval_init(void)
reg_fun(intern(lit("retf"), user_package), func_n1(retf));
reg_fun(apf_s, func_n1(apf));
reg_fun(ipf_s, func_n1(ipf));
+ reg_fun(intern(lit("callf"), user_package), func_n1v(callf));
reg_fun(intern(lit("tf"), user_package), func_n0v(tf));
reg_fun(intern(lit("nilf"), user_package), func_n0v(nilf));
diff --git a/txr.1 b/txr.1
index 95cfdb29..1c7a0aff 100644
--- a/txr.1
+++ b/txr.1
@@ -21414,6 +21414,38 @@ macro.
(call [apf +] '(1 2 3)) -> 6
.cble
+.coNP Function @ callf
+.synb
+.mets (callf < main-function << arg-function *)
+.syne
+.desc
+The
+.code callf
+function returns a function which applies its arguments to each
+.metn arg-function ,
+juxtaposing the return values of these calls to form arguments
+which are then passed to
+.metn main-function .
+The return value of
+.meta main-function
+is returned.
+
+The following equivalence holds, except for the order of evaluation of
+arguments:
+
+.cblk
+ (callf fm f0 f1 f2 ...) <--> (chain (juxt f0 f1 f2 ...) (apf fm))
+.cble
+
+.TP* Example:
+
+.cblk
+ ;; Keep those pairs which are two of a kind
+
+ (keep-if [callf eql first second] '((1 1) (2 3) (4 4) (5 6)))
+ -> ((1 1) (4 4))
+.cble
+
.SS* Input and Output (Streams)
\*(TL supports input and output streams of various kinds, with
generic operations that work across the stream types.