如何在LISP中将一个列表与另一个列表进行比较,并避免由于未定义变量而导致的求值错误?

如何在LISP中将一个列表与另一个列表进行比较,并避免由于未定义变量而导致的求值错误?,lisp,common-lisp,clisp,Lisp,Common Lisp,Clisp,我试着在CommonLisp中比较两个列表,如果它们匹配,则打印“RobotRobbie”。其中一个输入是用户给定的列表(存储在wff中),另一个输入是来自称为“nums”的列表列表的列表。但是,当我运行代码时,会出现以下错误: - EVAL: undefined function X 为什么会发生这种情况?我该如何解决?我已在下面附上我的代码以供参考: (defun same-elements (l1 l2) (and (subsetp l1 l2) (subsetp l2 l1)))

我试着在CommonLisp中比较两个列表,如果它们匹配,则打印“RobotRobbie”。其中一个输入是用户给定的列表(存储在wff中),另一个输入是来自称为“nums”的列表列表的列表。但是,当我运行代码时,会出现以下错误:

- EVAL: undefined function X
为什么会发生这种情况?我该如何解决?我已在下面附上我的代码以供参考:

(defun same-elements (l1 l2)
  (and (subsetp l1 l2) (subsetp l2 l1)))


(defun answer-ynq()
;;;Defining the hash-table

  (setq nums '(13 15 19 33))
  (setq numsstuff '())

  (setq nums  (loop for i below 2
            collect (loop for e in '(Robot Robbie)
                  for j from 0
                  when (equal i j) collect '- else collect e)))
  (print nums)

  (print "Hello, please enter a command")
  (setq wff (read-delimited-list #\~))
  (terpri)
  (loop for x in nums
    do (if (same-elements (x wff))
                  (print "(ROBOT ROBBIE)")

                  ))

)


  (answer-ynq)
试试这个:

(defun same-elements (l1 l2)
  (and (subsetp l1 l2) (subsetp l2 l1)))


(defun answer-ynq()
;;;Defining the hash-table

  (setq nums '(13 15 19 33))
  (setq numsstuff '())

  (setq nums  (loop for i below 2
            collect (loop for e in '(Robot Robbie)
                  for j from 0
                  when (equal i j) collect '- else collect e)))
  (print nums)

  (print "Hello, please enter a command")
  (setq wff (read-delimited-list #\~))
  (terpri)
  (loop for x in nums
    do (if (same-elements x wff)
                  (print "(ROBOT ROBBIE)")

                  ))

)


(answer-ynq)
唯一需要的更改是
(相同元素x wff)

(相同元素(x wff))
表示调用函数x,然后将结果传递给相同元素。不是你想要的


注释:正如其他人指出的那样,这样使用Stq不是一个好主意。

Lisp函数调用的语法是什么?你应该总是使用<代码>让< <代码> >你使用<代码> Stq我总是很高兴看到新的人学习CL,但是你应该考虑花一些时间来研究优秀的资源。习惯CL的语法和样式,您将自己理解错误消息。对于所有其他问题,您可以在这里找到很好的反馈。
(x wff)
是一个函数调用。使用参数WFF调用函数X。
X
是函数吗?错误不是关于未定义的变量(参见问题标题),而是关于未定义的函数(参见错误消息)。