Loops Lisp,而函数未定义错误与CLISP?

Loops Lisp,而函数未定义错误与CLISP?,loops,while-loop,lisp,common-lisp,clisp,Loops,While Loop,Lisp,Common Lisp,Clisp,我正在用LISP编写一个程序,使用CLISP运行该程序 我的函数中有一个while语句,但CLISP正在返回 *** - EVAL: undefined function WHILE 功能一点也不奇怪 (defun heap-insert (heap item key) "Put an item into a heap. [Page 150 CL&R]." ;; Note that ITEM is the value to be inserted, and KEY is a f

我正在用LISP编写一个程序,使用CLISP运行该程序

我的函数中有一个while语句,但CLISP正在返回

*** - EVAL: undefined function WHILE
功能一点也不奇怪

(defun heap-insert (heap item key)
  "Put an item into a heap. [Page 150 CL&R]."
  ;; Note that ITEM is the value to be inserted, and KEY is a function
  ;; that extracts the numeric value from the item.
  (vector-push-extend nil heap)
  (let ((i (- (length heap) 1))
    (val (funcall key item)))
    (while (and (> i 0) (>= (heap-val heap (heap-parent i) key) val))
      do (setf (aref heap i) (aref heap (heap-parent i))
               i (heap-parent i)))
        (setf (aref heap i) item)))

Common Lisp中没有名为
的函数或宏(或“语句”),因此CLISP给出该错误消息是正确的


可能您想使用
循环
宏,该宏接受
while
作为其语法的一部分。

您在
while
之前错过了
循环

尝试:


在公共Lisp中没有标准的
,而在Emacs Lisp中有一个循环构造。然而,如果你想要一个,它是相对简单的实现

(defmacro while (condition &body body)
  `(loop while ,condition
      do (progn ,@body)))
(defmacro while (condition &body body)
  `(loop while ,condition
      do (progn ,@body)))