Previous: Reduction of Lists, Up: Lists
These procedures are like
list
andmake-list
, respectively, except that the returned lists are circular.circular-list
could have been defined like this:(define (circular-list . objects) (append! objects objects))
circular-list
is compatible with SRFI 1, but extended so that it can be called with no arguments.
Returns a newly allocated list consisting of the top-level 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)
Returns a list consisting of the top-level elements of list in reverse order.
reverse!
is likereverse
, except that it destructively modifies list. Because the result may not beeqv?
to list, it is desirable to do something like(set! x (reverse! x))
.
Sequence must be either a list or a vector. Procedure must be a procedure of two arguments that defines a total ordering on the elements of sequence. In other words, if x and y are two distinct elements of sequence, then it must be the case that
(and (procedure x y) (procedure y x)) => #fIf sequence is a list (vector),
sort
returns a newly allocated list (vector) whose elements are those of sequence, except that they are rearranged to be sorted in the order defined by procedure. So, for example, if the elements of sequence are numbers, and procedure is<
, then the resulting elements are sorted in monotonically nondecreasing order. Likewise, if procedure is>
, the resulting elements are sorted in monotonically nonincreasing order. To be precise, if x and y are any two adjacent elements in the result, where x precedes y, it is the case that(procedure y x) => #fTwo sorting algorithms are implemented:
merge-sort
andquick-sort
. The proceduresort
is an alias formerge-sort
.See also the definition of
sort!
.