; An association list is a list of lists, where the ; first element in each sublist is the key to the ; elements found in that sublit. Association lists ; are useful for defining dictionaries, as in the ; following example: (define language-dict '((fortran "John Backus") (lisp "John McCarthy") (scheme "Guy Steele" "Gerry Sussman") (algol "John Backus" "Alan Perlis" "Peter Naur" "Edsger Dijkstra") (c "Dennis Ritchie" "Brian Kernighan") (clu "Barbara Liskov") (pascal "Niklaus Wirth") (modula "Niklaus Wirth") (c++ "Bjarne Stroustrup") (objective-C "Brad Cox") (perl "Larry Wall") (awk "Alfred Aho" "Glenn Weinberg" "Brian Kernighan") (java "James Gosling") (haskell "Paul Hudak" "Simon Peyton-Jones" "Phil Wadler") (miranda "David Turner") (ml "Robin Milner" "Larry Paulson") (simula "Ole-Johan Dahl" "Kristen Nygaard") (tcl "John Ousterhout") )) (define (lookup sym dict) (assoc sym dict)) (lookup 'algol language-dict) ; If you have a string, and want to conver it to a symbol ; to be used as the key into an access list, there are ; builtin scheme functions to map strings->symbols and ; symbols->strings. Here are a couple of examples: (lookup (string->symbol "java") language-dict) ; we can go the other direction and convert all ; the keys in the association list to a list of ; strings (map symbol->string (map car language-dict)) ; and then sort them using a sort function parameterized ; by the string comparison operator. We use the ; Dr. Scheme mergesort procedure from the list.ss ; library (define langs (map symbol->string (map car language-dict))) (mergesort langs string