cons
cons(g_elementl_list) =>l_result
Description
Adds an element to the beginning of a list. Thus the car of l_result is g_element and the cdr of l_result is l_list. l_list can be nil, in which case a new list containing the single element is created.
Arguments
Value Returned
|
List whose first element is g_element and whose |
Examples
cons(1 nil)
=> (1)
cons( 'a '(b c))
=> (a b c)
The following example shows how to efficiently build a list from 1 to 100. You can reverse the list if necessary.
x = nil
for( i 1 100 x = cons( i x ))
=> t
x
=> (100 99 98 .. 2 1)
x = reverse( x )
=> (1 2 3 .. 100)
Related Topics
Return to top