From c11346723fc9142c9199591f21ce1b4e1447b741 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 22 Dec 2011 22:34:12 -0800 Subject: * txr.1: Documented copy-list, reverse, nreverse, ldiff and flatten. --- ChangeLog | 4 +++ txr.1 | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/ChangeLog b/ChangeLog index 246beda7..990fa3e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-12-22 Kaz Kylheku + + * txr.1: Documented copy-list, reverse, nreverse, ldiff and flatten. + 2011-12-22 Kaz Kylheku * txr.1: Documented reduce-left and reduce-right. diff --git a/txr.1 b/txr.1 index 75fb84f9..63de5fc0 100644 --- a/txr.1 +++ b/txr.1 @@ -5522,12 +5522,115 @@ Examples: .SS Function copy-list +.TP +Syntax: + +(copy-list ) + +.TP +Description: + +The copy-list function which returns a list similar , but with +a newly allocated cons cell structure. + +If is an atom, it is simply returned. + +Otherwise, is a cons cell, and copy-list returns +(cons (car ) (copy-list (cdr ))) except that recursion +is not used. + +.TP +Dialect Note: + +Common Lisp does not allow the argument to be an atom, except +for the empty list nil. + .SS Functions reverse, nreverse +.TP +Syntax: + +(reverse ) +(nreverse ) + +.TP +Description: + +The functions reverse and nreverse produce an object which contains +the same items as proper list , but in reverse order. +If is nil, then both functions return nil. + +The reverse function is non-destructive: it creates a new list. + +The nreverse function creates the structure of the reversed list out of the +cons cells of the input list, thereby destructively altering it (if it contains +more than one element). How nreverse uses the material from the original list +is unspecified. It may rearrange the cons cells into a reverse order, or it may +keep the structure intact, but transfer the "car" values among cons cells into +reverse order. Other approaches are possible. + .SS Function ldiff +.TP +Syntax: + +(ldiff ) + +.TP +Description: + +The values and are proper lists. + +The ldiff function determines whether is a structural suffix of + (meaning that it actually is a suffix, and is not merely equal to one). + +This is true if and are the same object, or else, +recursively, if is a suffix of (cdr ). + +The object nil is the sublist of every list, including itself. + +The ldiff function returns a new list consisting of the elements of +the prefix of which come before the suffix. The elements +are in the same order as in . If is not a suffix of , +then a copy of is returned. + +.TP +Examples: + +;;; unspecified: the compiler could make '(2 3) a suffix of '(1 2 3), +;;; or they could be separate objects. +(ldiff '(1 2 3) '(2 3)) -> either (1) or (1 2 3) + +;; b is the (1 2) suffix of a, so the ldiff is (1) +(let ((a '(1 2 3)) (b (cdr a))) + (ldiff a b)) +-> (1) + .SS Function flatten +.TP +Syntax: + +(flatten ) + +.TP +Description: + +The flatten function produces a list whose elements are all of the non-nil +atoms contained in the structure of . + +.TP +Examples: + +(flatten '(1 2 () (3 4))) -> (1 2 3 4) + +;; precisely equivalent to previous example! nil is the same thing as () +(flatten '(1 2 nil (3 4))) -> (1 2 3 4) + +(flatten nil) -> nil + +(flatten '(((()) ()))) -> nil + .SS Functions memq and memqual .SS Function tree-find -- cgit v1.2.3