car
, cdr
, cons
, append
, reverse
, length
car()
: arbitrary, cdr()
, cons()
, append()
, reverse()
: list, length()
: non-negative integer
car()
outputs the first element of a non-null list.
For a null list, the result should be undefined. In the current
implementation, however, it outputs a null list. This treatment for a
null list may subject to change in future, and users are suggested not
to use the tentative treatment for a null list for serious programming.
cdr()
outputs a list obtained by removing the first
element from the input non-null list.
For a null list, the result should be undefined. In the current
implementation, however, it outputs a null list. This treatment for a
null list may subject to change in future, and users are suggested not
to use the tentative treatment for a null list for serious programming.
cons()
composes a new list from the input list list
and an arbitrary object obj by adding obj to the top of
list.
append()
composes a new list, which has all elements of
list1 in the same ordering followed by all elements of list2
in the same ordering.
reverse()
returns a reversed list of list.
length()
returns a non-negative integer which is the
number of elements in the input list list.
Note that function size
should be used for counting elements
of vector and matrix.
cdr()
n times repeatedly and cdr()
at last.
A more convenient way to access to the n-th element is the use
of bracket notation, that is, to attach an index [n]
like vectors and matrices. The system, however, follow the
n pointers to access the desired element. Subsequently, much
time is spent for an element located far from the top of the list.
cdr()
does not create a new cell (a memory quantity).
Function append()
, as a matter of fact, repeats cons()
for as many as the length of list1 the first argument.
Subsequently, append()
consumes much memory space if its
first argument is long.
Similar argument applies to function reverse()
.
[0] L = [[1,2,3],4,[5,6]]; [[1,2,3],4,[5,6]] [1] car(L); [1,2,3] [2] cdr(L); [4,[5,6]] [3] cons(x*y,L); [y*x,[1,2,3],4,[5,6]] [4] append([a,b,c],[d]); [a,b,c,d] [5] reverse([a,b,c,d]); [d,c,b,a] [6] length(L); 3 [7] L[2][0]; 5
Go to the first, previous, next, last section, table of contents.