; this uses the CLOS: Common LISP Object System ; First define a new class of objects called STACK (setq STACK (send Class :new nil)) ; send the STACK class instructions on how to do methods/operations (send STACK :isnew '(data head)) ; constructor describes two attributes (send STACK :answer :clear nil '((setq data nil)) ) (send STACK :answer :pop nil '((setq head (car data)) (setq data (cdr data)) head ) ) (send STACK :answer :push '(new) '((setq data (cons new data))) ) (send STACK :answer :top nil '((car data))) (send STACK :answer :empty nil '((null data))) ; some utilities used for unit testing (define (showdo c) (PROGN () (print C) (eval C)(print '-------)) ) (define (showval c) (PROGN () (prin1 C) (prin1 '=) (print (eval C)) (print '-------)) ) ; tests (showdo '(send STACK :show)) (setq mystack (send STACK :new)) (showdo '(send mystack :show)) (showdo '(send mystack :clear)) (showval '(send mystack :empty)) (showdo '(send mystack :push 1)) (showval '(send mystack :empty)) (showdo '(send mystack :show)) (showdo '(send mystack :push 2)) (showval '(send mystack :top)) (showval '(send mystack :pop) ) (showval '(send mystack :pop) ) (showdo '(send mystack :show))