本文介绍了什么是“函子中的非法论证”?在普通Lisp中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意学习Lisp

我遇到此错误:

Illegal argument in functor position: (EVALEXP (CDR MAIN-LIST) BIND-LIST)
in ((EVALEXP(CDR   MAIN-LIST) BIND-LIST))

来自此:

(defun evalexp (main-list bind-list)

(if (eq nil (cdr main-list))
    (  (if  (eq nil  (atom (car main-list))) (evalexp (car main-list) bind-list) ) )

( (print (car main-list))
  (evalexp (cdr main-list) bind-list) )
)

主列表包含以下列表:

(and 1 (or a b))

绑定列表中的内容无关紧要,因为我还没有使用它。我试图遍历列表以打印出每辆汽车。我为什么会遇到此错误?

What is in bind-list doesn't matter because I am not using it yet. I am trying to loop through the list printing out each car. Any ideas why I am getting this error?

推荐答案

额外的括号。

通常,左括号后的第一件事是函数名称。在某些情况下,您还会看到另一个括号,如您所见,这是语法错误。

Normally the first thing after an opening parenthesis is a function name. You have another opening parenthesis there in some cases, which is a syntax error, as you saw.

您似乎还希望使用语句块。 progn 通常很合适。您可以对内部 if 使用一个块,但这实际上不是必需的,因为它只包含一个语句。

You also seem to want a statement block. progn often fits the bill. You could use a block for the inner if, but it's really not necessary since it would contain only one statement.

(defun evalexp (main-list bind-list)
  (if (eq nil (cdr main-list))
      (if  (eq nil (atom (car main-list))) (evalexp (car main-list) bind-list) )
      (progn
        (print (car main-list))
        (evalexp (cdr main-list) bind-list) )
  )
)

这篇关于什么是“函子中的非法论证”?在普通Lisp中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:44