Go to the first, previous, next, last section, table of contents.

### `car`, `cdr`, `cons`, `append`, `reverse`, `length`

`car(list)`
  :: The first element of the given non-null list list.
`cdr(list)`
  :: A list obtained by removing the first element of the given non-null list list.
`cons(obj,list)`
  :: A list obtained by adding an element obj to the top of the given list list.
``append`(list1,list2)`
  :: A list obtained by adding all elements in the list list2 according to the order as it is to the last element in the list list1.
``reverse`(list)`
  :: reversed list of list.
`length(list)`
  :: Number of elements in a list list.

return
  `car()` : arbitrary, `cdr()`, `cons()`, `append()`, `reverse()` : list, `length()` : non-negative integer
list list1 list2
  list
obj
  arbitrary

- A list is written in Asir as `[`obj1,obj2,...`]`. Here, obj1 is the first element.
- Function `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.
- Function `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.
- Function `cons()` composes a new list from the input list list and an arbitrary object obj by adding obj to the top of list.
- Function `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.
- Function `reverse()` returns a reversed list of list.
- Function `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.
- Lists are read-only objects in Asir. There elements cannot be modified.
- The n-th element in a list can be referred to by applying the function `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.
- Function `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.