MC logo

Simple A-List Demo


CS 231 Lecture Examples

<< Download >>
;
; The lisp phone book.  This uses a Lisp a-list to keep a simple phone
; book of names and numbers.
;

; This creates the empty book.
(setq phone_book nil)

; Add a name and number to the book
(defun ph_add (name num)
    (setq phone_book (acons name num phone_book))
)

; Lookup.
(defun ph_find (name)
    (let ((item (assoc name phone_book :test 'equal)))
         (if (or (null item) (null (cdr item))) "Not found." (cdr item))
    )
)

; Delete (which really just "covers" the entry)
(defun ph_delete (name)
    (add_number name nil)  
)

<<
>>