【问题标题】:list should be a lambda expressionlist 应该是一个 lambda 表达式
【发布时间】:2012-09-24 08:59:48
【问题描述】:

我刚刚开始学习 LISP,我只是在思考它的逻辑,但是我遇到了一个错误,我找不到解决方案。我确定这是因为我我在某处误用了括号,或者我在一般情况下误用了一个函数,但我已经盯着它看了一个小时,没有任何进展!

(defun not-touching (pos player move)
   (let (legal? t)
    if ((not (eq (member move '(0 1 2 3 4 7 8 11 12 13 14 15)) nil))
        (mapcar #'(lambda(x) (if (not (member move x) nil)
                                (cond ((and (eq (nth (- (position move x) 1) x) nil)
                                        (not (eq (nth (+ (position move x) 1) x) player))) t)   
                                    ((and (not (eq (nth (- (position move x) 1) x) player))
                                        (not (eq (nth (+ (position move x) 1) x) player))) t)
                                    ((and (not (eq (nth (- (position move x) 1) x) player))
                                        (eq (nth (+ (position move x) 1) x) nil)) t)
                                    (t setf legal? nil))
                                nil)) *outside-lines*))
    legal?))

我得到的错误如下所示:

SYSTEM::%EXPAND-FORM: (NOT (EQ (MEMBER MOVE '(0 1 2 3 4 7 8 11 12 13 14 15)) NIL)) should be
  a lambda expression

任何帮助将不胜感激!

【问题讨论】:

  • 括号太多。在not之前去掉一个,否则看起来像一个函数应用程序。而且您在let 中缺少括号。

标签: lambda lisp


【解决方案1】:

如果你想编程,你需要学习编程语言的语法。

请参阅Common Lisp Hyperspec 了解 Common Lisp 语法。 Common Lisp 的每个函数/宏/特殊运算符/...都在 Common Lisp Hyperspec 及其语法中进行了描述。

查看 LET、IF 的语法。

LET 需要一个绑定列表。

IF, SETF 是一种形式。需要括号括起来。

NOT 只接受一个参数。

【讨论】:

  • 谢谢 :) 而且我知道,这是一个学习曲线,我的讲师在语法方面几乎没有做任何事情,他只给出了一个基本的使用示例,其余的取决于你!
  • @user1693910:还好有很多资源可以学习。 Hyperspec 描述了该语言,有免费书籍,良好的编译器(如 Clozure CL 和 SBCL),...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
相关资源
最近更新 更多