summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-02 15:22:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-02 15:22:49 -0800
commit1d6ad5892120dd0ce3f1947ee87fe343fc932f0d (patch)
treed45fbe1a2ac898d768b075f0cfd6a401ddaef27c /eval.c
parentfd2690b7b18d46ea970f1ec828d7a35e31d4942b (diff)
downloadtxr-1d6ad5892120dd0ce3f1947ee87fe343fc932f0d.tar.gz
txr-1d6ad5892120dd0ce3f1947ee87fe343fc932f0d.tar.bz2
txr-1d6ad5892120dd0ce3f1947ee87fe343fc932f0d.zip
append can now take additional leading arguments before the list.
* eval.c (apply_frob_args): New static function. (apply_intrinsic): Process arguments with apply_frob_args. (eval_init): apply_intrinsic registered differently, as a variadic function with one mandatory arg. * lib.c (lastcons): New function. * lib.h (lastcons): Declared. * txr.1: Updated append documentation.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 888c7e49..92922bd7 100644
--- a/eval.c
+++ b/eval.c
@@ -419,9 +419,20 @@ val apply(val fun, val arglist, val ctx_form)
internal_error("corrupt function type field");
}
+static val apply_frob_args(val args)
+{
+ val *plast = lastcons(args);
+ if (plast) {
+ *plast = car(*plast);
+ return args;
+ } else {
+ return car(args);
+ }
+}
+
static val apply_intrinsic(val fun, val args)
{
- return apply(fun, args, cons(apply_s, nil));
+ return apply(fun, apply_frob_args(args), cons(apply_s, nil));
}
static val do_eval(val form, val env, val ctx_form,
@@ -2384,7 +2395,7 @@ void eval_init(void)
reg_fun(intern(lit("mapcar*"), user_package), func_n1v(lazy_mapcarv));
reg_fun(intern(lit("mappend"), user_package), func_n1v(mappendv));
reg_fun(intern(lit("mappend*"), user_package), func_n1v(lazy_mappendv));
- reg_fun(apply_s, func_n2(apply_intrinsic));
+ reg_fun(apply_s, func_n1v(apply_intrinsic));
reg_fun(intern(lit("reduce-left"), user_package), func_n4o(reduce_left, 2));
reg_fun(intern(lit("reduce-right"), user_package), func_n4o(reduce_right, 2));