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

constar

constar( 
[ g_arg1 ... ] 
l_list 
) 
=> l_result

Description

Adds elements to the beginning of a list.

This function is equivalent to cons\*() and should be used instead.

The last argument, l_list, must be a list. l_list can be nil, in which case a new list containing the elements is created.The car of l_result is the first argument passed to constar() and the cdr of l_result is rest of the elements of the newly created list (including l_list).

Arguments

[ g_arg1 ... ]

Elements to be added to the beginning of l_list.

l_list

The last argument that must be a list (which can be nil).

Value Returned

l_result

List whose first element is the first argument and whose cdr is rest of the elements of the newly created list (including l_list).

Examples

The first element of the newly created list is the first argument while cdr is rest of the elements (including l_list):

newList = constar( '(a b) '("hello") 1 2.3 '(x y) )
=> ((a b) ("hello") 1 2.3 x y z)
car( newList ) => (a b)
cdr( newList ) => (("hello") 1 2.3 x y z)

The last argument can be nil:

constar( 1 2 3 nil ) => (1 2 3)

The last argument must be a list:

constar( 'x 1 2 )
*Error* constar: the last arg must be a list - 2

constar() is cleaner and more efficient in adding multiple elements to the beginning of a list than cons():

cons(1 cons(2 cons(3 '(a b c)))) => (1 2 3 a b c)
constar( 1 2 3 '(a b c)) => (1 2 3 a b c)

Related Topics

car

cdr

append

append1


Return to top
 ⠀
X