Node: Association Lists, Previous: Using Lists as Sets, Up: Lists

Association Lists

An association list is a list of pairs where each pair is an association of a key to a datum. The pair is represented as a cons where the car is the key of the pair and the cdr is the datum.

assoc key list Function

assoc key list test Function

assoc searches for a cons in list whose car is eql to key. If found, the cons is returned otherwise nil is returned. If the optional third argument test is given it must be an Lpp Function of two arguments and assoc will use it to do the test in place of eql. For example:

     let list1 = list(cons(L(1), L(2)),
                      cons(L(2), L(4)), cons(L(3), L(6)));
     assoc(L(2), list1) => (2 . 4)
     assoc(L(4), list1) => nil
     let list1 = list(list(L("1"), L(2)),
                      list(L("2"), L(4)), list(L("3"), L(6)));
     assoc(L("2"), list1) => nil
     assoc(L("2"), list1, L(stringEqual)) => ("2" 4)