summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-20 06:48:06 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-20 06:48:06 -0700
commite21a452a9c75074ab7eff33b70950aecf3f3c309 (patch)
tree5b8f5301ce2584532ae1b8858833ca420b948535
parent2a9b3bca2622a54434cc16e7c70dce37b1c4d205 (diff)
downloadtxr-e21a452a9c75074ab7eff33b70950aecf3f3c309.tar.gz
txr-e21a452a9c75074ab7eff33b70950aecf3f3c309.tar.bz2
txr-e21a452a9c75074ab7eff33b70950aecf3f3c309.zip
* eval.c (do_apf, apf): New functions.
(eval_init): Register apf as intrinsic. * txr.1: Document apf.
-rw-r--r--ChangeLog7
-rw-r--r--eval.c11
-rw-r--r--txr.127
3 files changed, 45 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f325509..bb8884cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2014-06-20 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (do_apf, apf): New functions.
+ (eval_init): Register apf as intrinsic.
+
+ * txr.1: Document apf.
+
+2014-06-20 Kaz Kylheku <kaz@kylheku.com>
+
Improve error reporting.
* eval.c (eval_error): Use last_form_evaled if form is null.
diff --git a/eval.c b/eval.c
index 96bbfe05..c5e024ee 100644
--- a/eval.c
+++ b/eval.c
@@ -3104,6 +3104,16 @@ static val retf(val ret)
return func_f0v(ret, do_retf);
}
+static val do_apf(val fun, val args)
+{
+ return apply(fun, args, nil);
+}
+
+static val apf(val fun)
+{
+ return func_f1(fun, do_apf);
+}
+
static val prinl(val obj, val stream)
{
val ret = obj_print(obj, stream);
@@ -3456,6 +3466,7 @@ void eval_init(void)
reg_fun(intern(lit("or"), user_package), func_n0v(or_fun));
reg_fun(intern(lit("and"), user_package), func_n0v(and_fun));
reg_fun(intern(lit("retf"), user_package), func_n1(retf));
+ reg_fun(intern(lit("apf"), user_package), func_n1(apf));
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 7d443afb..e325c471 100644
--- a/txr.1
+++ b/txr.1
@@ -11957,6 +11957,8 @@ except that the symbol args is to be understood as a generated symbol (gensym).
The ap macro nests properly with op and do, in any combination, in regard
to the @@n notation.
+See also: the apf function.
+
.SS Macro ret
.TP
@@ -12157,6 +12159,31 @@ Example:
;; the function returned by (retf 42) ignores 1 2 3 and returns 42.
(call (retf 42) 1 2 3) -> 42
+.SH Function apf
+
+.TP
+Syntax:
+
+ (apf <function>)
+
+.TP
+Description:
+
+The apf function returns a one-argument function which accepts
+a list. When the function is called, it treats the list as
+argument which are applied to <function>. It returns whatever
+<function> returns.
+
+See also: the ap macro.
+
+.TP
+Example:
+
+ ;; Function returned by [apf +] accepts (1 2 3) list and
+ ;; applies it to +, as if (+ 1 2 3) were called.
+
+ (call [apf +] '(1 2 3)) -> 6
+
.SH INPUT AND OUTPUT (STREAMS)
TXR Lisp supports input and output streams of various kinds, with