From fca47effb1490e6308be3f9600fe782f3cdea862 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 23 Jan 2014 00:17:33 -0800 Subject: * lib.c (conses, lazy_conses, func_set_env): New functions. (lazy_conses_func): New static function. * lib.h (conses, lazy_conses, func_set_env): Declared. * eval.c (eval_init): conses, lazy_conses and func_set_env registered as intrinsics. * txr.1: Documented. --- txr.1 | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 8c7683e9..ed33cfae 100644 --- a/txr.1 +++ b/txr.1 @@ -7027,12 +7027,58 @@ Examples: (mappend (lambda (item) (if (evenp x) (list x))) '(1 2 3 4 5)) -> (2 4) +.SS Functions conses and conses* + +.TP +Syntax: + + (conses ) + (conses* ) + +.TP +Description: + +These functions return a list whose elements are the conses which make +up . The conses* function does this in a lazy way, avoiding the +computation of the entire list: it returns a lazy list of the conses of . +The conses function computes the entire list before returning. + +The input may be proper or improper. + +The first cons of a list is that list itself. The second cons is the rest +of the list, or (cdr ). The third cons is (cdr (cdr )) and so on. + +.TP +Example: + + (conses '(1 2 3)) -> ((1 2 3) (2 3) (3)) + +.TP +Dialect Note: + +These functions are useful for simulating the maplist function found in +other dialects like Common Lisp. + +TXR Lisp's (conses x) can be expressed in Common Lisp as +(maplist #'identity x). + +Conversely, the Common Lisp operation (maplist function list) can be computed +in TXR Lisp as (mapcar function (conses list)). + +More generally, the Common Lisp operation + + (maplist function list0 list1 ... listn) + +can be expressed as: + + (mapcar function (conses list0) (conses list1) ... (conses listn)) + .SS Function apply .TP Syntax: -(apply ) + (apply ) .TP Description: -- cgit v1.2.3