Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

cons

cons( 
g_element 
l_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

g_element

Element to be added to the beginning of l_list.

l_list

List that can be nil.

Value Returned

l_result

List whose first element is g_element and whose cdr is l_list.

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

car

cdr

append

append1


Return to top
 ⠀
X