summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-02 15:35:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-02 15:37:55 -0800
commita5c639d6bbb5c2bb6720fa69086f9187452192f6 (patch)
treedca305b48314270bb35f567c956c8f68564e0f6f
parent1d6ad5892120dd0ce3f1947ee87fe343fc932f0d (diff)
downloadtxr-a5c639d6bbb5c2bb6720fa69086f9187452192f6.tar.gz
txr-a5c639d6bbb5c2bb6720fa69086f9187452192f6.tar.bz2
txr-a5c639d6bbb5c2bb6720fa69086f9187452192f6.zip
Adding list* since we get it "for free" thanks to the
new helper function that supports apply. * eval.c (list_star_intrinsic): New static function. (eval_init): Register list_star_intrinsic as list*. * txr.1: Document list*.
-rw-r--r--ChangeLog10
-rw-r--r--eval.c6
-rw-r--r--txr.136
3 files changed, 52 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 508f4cd2..e57911b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2014-02-02 Kaz Kylheku <kaz@kylheku.com>
+ Adding list* since we get it "for free" thanks to the
+ new helper function that supports apply.
+
+ * eval.c (list_star_intrinsic): New static function.
+ (eval_init): Register list_star_intrinsic as list*.
+
+ * txr.1: Document list*.
+
+2014-02-02 Kaz Kylheku <kaz@kylheku.com>
+
append can now take additional leading arguments before the list.
* eval.c (apply_frob_args): New static function.
diff --git a/eval.c b/eval.c
index 92922bd7..cff8b997 100644
--- a/eval.c
+++ b/eval.c
@@ -435,6 +435,11 @@ static val apply_intrinsic(val fun, val args)
return apply(fun, apply_frob_args(args), cons(apply_s, nil));
}
+static val list_star_intrinsic(val args)
+{
+ return apply_frob_args(args);
+}
+
static val do_eval(val form, val env, val ctx_form,
val (*lookup)(val env, val sym));
@@ -2380,6 +2385,7 @@ void eval_init(void)
reg_fun(append_s, func_n0v(appendv));
reg_fun(intern(lit("append*"), user_package), func_n0v(lazy_appendv));
reg_fun(list_s, func_n0v(identity));
+ reg_fun(intern(lit("list*"), user_package), func_n1v(list_star_intrinsic));
reg_fun(intern(lit("identity"), user_package), identity_f);
reg_fun(intern(lit("typeof"), user_package), func_n1(typeof));
diff --git a/txr.1 b/txr.1
index e988e36c..97a3f10c 100644
--- a/txr.1
+++ b/txr.1
@@ -6585,6 +6585,42 @@ Examples:
(list 1) -> (1)
(list 'a 'b) -> (a b)
+.SS Function list*
+
+.TP
+Syntax:
+
+(list* {<value>}*)
+
+.TP
+Description:
+
+The list* function is a generalization of cons. If called with exactly
+two arguments, it behaves exactly like cons: (list* x y) is
+identical to (cons x y). If three or more arguments are specified,
+the leading arguments specify additional atoms to be consed to the
+front of the list. So for instance (list* 1 2 3) is the same as
+(cons 1 (cons 2 3)) and produces the improper list (1 2 . 3).
+Generalizing in the other direction, list* can be called with just
+one argument, in which case it returns that argument, and
+can also be called with no arguments in which case it returns nil.
+
+.TP
+Examples:
+
+ (list*) -> nil
+ (list* 1) -> 1
+ (list* 'a 'b) -> (a . b)
+ (list* 'a 'b 'c) -> (a b . c)
+
+.TP
+Dialect Note:
+
+Note that unlike in some other Lisp dialects, the effect
+of (list* 1 2 x) can also be obtained using (list 1 2 . x).
+However, (list* 1 2 (func 3)) cannot be rewritten as (list 1 2 . (func 3))
+because the latter is equivalent to (list 1 2 func 3).
+
.SS Function sub-list
.TP