; defines an object that fits the stack ADT ; usage: (new), (top), (push it), (pop), ... (let ((stack nil)) ; local variable holds the stack access only by defuns below (defun new () (setq stack nil)) ; defun functions have global scope (defun top () (car stack)) (defun push (item) (setq stack (cons item stack))) (defun pop () (setq stack (cdr stack))) (defun empty () (null stack)) ) ; tests ; (push 1) ; (top) ; (push 2) ; (top) ; (pop) ; (top) ; (pop) ; (empty)