Within literal expressions, the forms 'datum,
&grave.datum, ,datum, and
,datum denote the two-element list whose first
element are the symbols quote, quasiquote, unquote,
and unquote-splicing, respectively. The second element in each
case is datum. This convention is supported so that arbitrary
expressions and portions of the specification may be represented as
lists. That is, according to the DSSSL expression language grammar,
every expression is also a datum, and a
transformation-language-body is a sequence of datums.
8.5.3.1 Pair Type Predicate
(pair? obj)
Returns #t if obj is a pair, and otherwise
returns #f.
(pair? '(a . b)) #t
(pair? '(a b c)) #t
(pair? '()) #f
8.5.3.2 Pair Construction Procedure
(cons obj1 obj2)
Returns a pair whose car is obj1 and whose cdr is
obj2.
(cons 'a '()) (a)
(cons '(a) '(b c d)) ((a) b c d)
(cons "a" '(b c)) ("a" b c)
(cons 'a 3) (a . 3)
(cons '(a b) 'c) ((a b) . c)
8.5.3.3 car Procedure
(car pair)
Returns the contents of the car field of pair. Note that it shall be an
error to take the car of the empty list.
(car '(a b c)) a
(car '((a) b c d)) (a)
(car '(1 . 2)) 1
(car '()) error
8.5.3.4 cdr Procedure
(cdr pair)
Returns the contents of the cdr field of pair.
Note that it shall be an error to take the cdr of the empty list.
(cdr '((a) b c d)) (b c d)
(cdr '(1 . 2)) 2
(cdr '()) error
8.5.3.5 cr Procedures
(caar pair)
(cadr pair)
(cdar pair)
(cddr pair)
(caaar pair)
(caadr pair)
(cadar pair)
(caddr pair)
(cdaar pair)
(cdadr pair)
(cddar pair)
(cdddr pair)
(caaaar pair)
(caaadr pair)
(caadar pair)
(caaddr pair)
(cadaar pair)
(cadadr pair)
(caddar pair)
(cadddr pair)
(cdaaar pair)
(cdaadr pair)
(cdadar pair)
(cdaddr pair)
(cddaar pair)
(cddadr pair)
(cdddar pair)
(cddddr pair)
These procedures are compositions of car and cdr, where
for example caddr could be defined by
(define caddr (lambda (x) (car (cdr (cdr x))))).
Arbitrary compositions, up to four deep, are provided. There are
twenty-eight of these procedures in all.
8.5.3.6 Empty List Type Predicate
(null? obj)
Returns #t if obj is the empty list, and
otherwise returns #f.
8.5.3.7 List Type Predicate
(list? obj)
Returns #t if obj is a list, and otherwise returns
#f.
By definition, all lists have finite length and are terminated by
the empty list.
(list? '(a b c)) #t
(list? '()) #t
(list? '(a . b)) #f
8.5.3.8 List Construction
(list obj )
Returns a list of its arguments.
(list 'a (+ 3 4) 'c) (a 7 c)
(list) ()
8.5.3.9 List Length
(length list)
Returns the length of list.
(length '(a b c)) 3
(length '(a (b) (c d e))) 3
(length '()) 0
8.5.3.10 Lists Appendance
(append list )
Returns a list consisting of the elements of the first list
followed by the elements of the other lists.
(append '(x) '(y)) (x y)
(append '(a) '(b c d)) (a b c d)
(append '(a (b)) '((c))) (a (b) (c))
The last argument may actually be any object; an improper list results
if the last argument is not a proper list.
(append '(a b) '(c . d)) (a b c . d)
(append '() 'a) a
8.5.3.11 List Reversal
(reverse list)
Returns a list consisting of the elements of list
in reverse order.
(reverse '(a b c)) (c b a)
(reverse '(a (b c) d (e (f)))) ((e (f)) d (b c) a)
8.5.3.12 Sublist Extraction
(list-tail list k)
Returns the sublist of list obtained by omitting the first k
elements.
List-tail could be defined by
(define list-tail
(lambda (x k)
(if (zero? k)
x
(list-tail (cdr x) (- k 1)))))
8.5.3.13 List Access
(list-ref list k)
Returns the kth element of list. (This is the same
as the car of (list-tail list k).)
(list-ref '(a b c d) 2) c
(list-ref '(a b c d)
(inexact->exact (round 1.8))) c
8.5.3.14 List Membership
(member obj list)
Returns the first sublist of list whose car is
equal? to
obj, where the sublists of list are the non-empty lists
returned by (list-tail list k) for k less
than the length of list. If
obj does not occur in list, then #f (not the empty list) is
returned.
(member 'a '(a b c)) (a b c)
(member 'b '(a b c)) (b c)
(member 'a '(b c d)) #f
8.5.3.15 Association Lists
(assoc obj alist)
alist (for association list) shall be a list of pairs. This
procedure finds the first pair in alist whose car field is
equal? to obj and returns that pair. If no pair in
alist has obj as its car, then #f (not the empty list)
is returned.
(define e '((a 1) (b 2) (c 3)))
(assoc 'a e) (a 1)
(assoc 'b e) (b 2)
(assoc 'd e) #f
| Although they are ordinarily used as predicates, member and
assoc do not have question marks in their names because they
return useful values rather than just #t or #f. |
|