All pastes #90633 Raw Edit

Stuff

public text v1 · immutable
#90633 ·published 2006-07-17 21:44 UTC
rendered paste body
;;; Address Book
;;; By: Colin Drake
;;; Written in response to http://mypage.iu.edu/~colallen/lp/node57.html
;;; Written for Common LISP


;; Person Structure
(defstruct person
    first-name 
    last-name
    address
    age
    gender
    kids)


;; Example People
(setf Billy (make-person :first-name 'Billy
                         :last-name  'Joe
                         :address    "1234 Maple Street"
                         :age        15
                         :gender     'male
                         :kids       ()))
(setf Bob (make-person   :first-name 'Bob
                         :last-name  'Joe
                         :address    "1234 Maple Street"
                         :age        11
                         :gender     'male
                         :kids       ()))
(setf David (make-person :first-name 'David
                         :last-name  'Joe
                         :address    "1234 Maple Street"
                         :age        41
                         :gender     'male
                         :kids       '(Billy Bob)))


;; Should print all kids of David?
(setq r 0)
; gives "*** - SYSTEM::%STRUCTURE-REF: BILLY is not a structure of
;   type PERSON"
(dolist (n (person-kids David) r)(person-first-name n))