我还在学习 Lisp 语言,我需要了解如何使用 Lisp 实现堆栈(需要 push-pop-peek 函数。)。此外,我在寻求帮助时发现了此代码。但我不确定它是否正常工作。
(defstruct stack
elements)
(defun stack-push (element stack)
(push element (stack-elements stack)))
(defun stack-pop (stack)(deftype Stack [elements])
(defun stack-empty (stack)
(endp (stack-elements stack)))
(defun stack-top (stack)
(first (stack-elements stack)))
(defun stack-peek (stack)
(stack-top stack))