diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-02-02 15:35:18 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-02-02 15:37:55 -0800 |
commit | a5c639d6bbb5c2bb6720fa69086f9187452192f6 (patch) | |
tree | dca305b48314270bb35f567c956c8f68564e0f6f | |
parent | 1d6ad5892120dd0ce3f1947ee87fe343fc932f0d (diff) | |
download | txr-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-- | ChangeLog | 10 | ||||
-rw-r--r-- | eval.c | 6 | ||||
-rw-r--r-- | txr.1 | 36 |
3 files changed, 52 insertions, 0 deletions
@@ -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. @@ -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)); @@ -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 |