## Operations on Lists

The<list>class is partitioned into two subclasses,<pair>and<empty-list>. The classes<list>,<pair>, and<empty-list>are sealed; users cannot create new subclasses of<list>.An

improper listis a list that is not terminated by the empty list, either because it is terminated by something that is not a list, or because it is circular and thus non-terminating. Except when their behavior on improper lists is documented explicitly, collection or sequence functions are not guaranteed to return an answer when an improper list is used as a collection or a sequence. At the implementation's option, these functions may return the correct result, signal a<type-error>, or (in the case of a circular list) fail to return.

pairhead tail=>pair[Function]

paircreates a new pair whose head and tail values are as indicated.?pair (1, 2)#(1 . 2) ?pair (1, #(2, 3, 4, 5))#(1, 2, 3, 4, 5)

list#restargs=>list[Function]

listreturns a list of theargs, in order.?list (1, 2, 3)#(1, 2, 3) ?list (4 + 3, 4 - 3)#(7, 1)

headlist=>object[Function]

Iflistis a pair, this function returns the value of the head slot. Otherwise,listis the empty list, andheadreturns the empty list.?head (#(4, 5, 6))4 ?head (#())#()

taillist=>object[Function]

Iflistis a pair, this function returns the value of the tail slot. Otherwise,listis the empty list, andtailreturns the empty list.?tail (#(4, 5, 6))#(5, 6) ?tail (#())#()

head-setterobject pair=>object[Function]

This function sets the head ofpairto containobjectand returnsobject.?define variable x = list (4, 5, 6)#(4, 5, 6) ?head (x) := 99 ?x#(9, 5, 6)

tail-setterobject pair=>object[Function]

This function sets the tail ofpairto containobjectand returnsobject.?define variable x = list (4, 5, 6)#(4, 5, 6) ?tail (x) := #(9, 8, 7)#(9, 8, 7) ?x#(4, 9, 8, 7)

add!list element=>pair[G.F. Method]

Equivalent to(pairelement list). That is, the result shares structure withlistbut will not be==tolist.

remove!list element#keytest count=>list[G.F. Method]

remove!destructively modifieslist. The result is not necessarily==tolist.

sizelist=>{integer or #f}[G.F. Method]

For circular lists,sizeis guaranteed to terminate and return#f. For non-circular lists,sizereturns an integer size value.

list1=list2=>boolean[G.F. Method]

For lists,=returns#funless the two lists are the same size, corresponding elements oflist1andlist2are=and the final tails are=.

list=sequence=>boolean[G.F. Method]sequence=list=>boolean[G.F. Method]

For mixed lists and sequences,Next section: Operations on Ranges=returns#funless thelistis not a dotted list, both have the same size, and elements with=keys are=.