Next: , Previous: List Constructors, Up: Lists


22.2.4 List Selection

These procedures are used to get some information about a list, or to retrieve one or more elements of a list.

— Scheme Procedure: length lst
— C Function: scm_length (lst)

Return the number of elements in list lst.

— Scheme Procedure: last-pair lst
— C Function: scm_last_pair (lst)

Return a pointer to the last pair in lst, signalling an error if lst is circular.

— Scheme Procedure: list-ref lst k
— C Function: scm_list_ref (lst, k)

Return the kth element from list lst.

— Scheme Procedure: list-tail lst k
— Scheme Procedure: list-cdr-ref lst k
— C Function: scm_list_tail (lst, k)

Return the "tail" of lst beginning with its kth element. The first element of the list is considered to be element 0.

list-cdr-ref and list-tail are identical. It may help to think of list-cdr-ref as accessing the kth cdr of the list, or returning the results of cdring k times down lst.

— Scheme Procedure: list-head lst k
— C Function: scm_list_head (lst, k)

Copy the first k elements from lst into a new list, and return it.