lambda中的非法函数调用

lambda中的非法函数调用,lambda,lisp,common-lisp,chess,Lambda,Lisp,Common Lisp,Chess,我正在研究一个函数来计算棋局中棋子的有效移动。白兵移动功能起作用。当我试图将其推广到任一玩家的棋子(棋子移动)时,我遇到了一个非法的函数调用。我已经在repl中测试了funcall,我认为这不是问题所在 我做错了什么 你能显示你得到的错误吗 我刚刚使用Emacs Lisp尝试了您的代码(将字符表示形式更改为Emacs Lisp),但是sexps(典当移动+)和(典当移动-)没有错误。是他们让你犯了错误吗?我为(典当移动+)得到了这个,例如: (lambda (file rank)

我正在研究一个函数来计算棋局中棋子的有效移动。白兵移动功能
起作用。当我试图将其推广到任一玩家的棋子(
棋子移动
)时,我遇到了一个非法的函数调用。我已经在repl中测试了funcall,我认为这不是问题所在

我做错了什么


你能显示你得到的错误吗

我刚刚使用Emacs Lisp尝试了您的代码(将字符表示形式更改为Emacs Lisp),但是sexps
(典当移动+)
(典当移动-)
没有错误。是他们让你犯了错误吗?我为
(典当移动+)
得到了这个,例如:

(lambda (file rank) (let ((movelist 'nil)) (if (and (within-boardp file (funcall direction rank 1)) (eql 115 (aref *board* (funcall direction rank 1) file))) (push (cons file (funcall direction rank 1)) movelist)) (if (= rank startrank) (push (cons file (funcall direction rank 2)) movelist)) (if (and (within-boardp (- file 1) (funcall direction rank 1)) (belongs-to-opponent (aref *board* (funcall direction rank 1) (- file 1)))) (push (cons (- file 1) (funcall direction rank 1)) movelist)) (if (and (within-boardp (+ file 1) (funcall direction rank 1)) (belongs-to-opponent (aref *board* (funcall direction rank 1) (+ file 1)))) (push (cons (+ file 1) (funcall direction rank 1)) movelist)) movelist)) (兰姆达(军衔) (let((移动列表‘无)) (如果(和)(在董事会内) 文件 (全方位排名1)) (eql 115 (aref*董事会* (全方位排名1) (文件号) (推送(cons文件(全方向排名1)) 移动列表) (如果(=等级startrank) (推送(cons文件(全方向秩2)) 移动列表) (如果(和)(在董事会内) (-文件1) (全方位排名1)) (属于对手) (aref*董事会*(全方位排名1) (-file 1))) (推送(cons(-file 1)(全方位排名1)) 移动列表) (如果(和)(在董事会内) (+文件1) (全方位排名1)) (属于对手) (aref*董事会* (全方位排名1) (+文件1))) (推送(cons(+文件1)(全方位排名1)) 移动列表) 移动列表)
总之,也许可以对您看到的内容提供更多详细信息。

您的
白典当移动
返回一个移动列表,而
典当移动
返回一个可以返回移动列表的函数。我猜您试图调用
(典当移动+)
,而您以前调用的是
(白典当移动)
,但是您必须调用
(funcall)(典当移动+)
,那么问题可能出在您的程序调用函数的方式上。我不知道问题为什么会结束。一般来说,我觉得这个问题没问题。请再次添加问题。但是在这里添加源代码(不要链接到外部托管代码)和一个测试用例,看看它是如何工作的,以及它是如何出错的。它关闭了,因为问题是“这个大件代码有问题”。其他人不太可能从中受益。如果这个问题可以归结为一个有重点、有针对性的问题,那么它就是一个话题。但就目前情况而言,它只是没有正确定义。@corsiKa:只要给出一点代码,我们就会发现一个非法的函数调用。在Lisp中,您有时必须费力地完成这一过程,这是一个很好的练习,可以向人们展示如何发现这样的错误。有些错误很容易减少,但调试稍大的代码也需要学习。所讨论的代码也不依赖于复杂的设置,因此有机会找到非法的函数调用并帮助解释错误消息。缺少的是更好地展示错误和代码。我缩小了问题的范围并发布了一个新问题。 (lambda (file rank) (let ((movelist 'nil)) (if (and (within-boardp file (funcall direction rank 1)) (eql 115 (aref *board* (funcall direction rank 1) file))) (push (cons file (funcall direction rank 1)) movelist)) (if (= rank startrank) (push (cons file (funcall direction rank 2)) movelist)) (if (and (within-boardp (- file 1) (funcall direction rank 1)) (belongs-to-opponent (aref *board* (funcall direction rank 1) (- file 1)))) (push (cons (- file 1) (funcall direction rank 1)) movelist)) (if (and (within-boardp (+ file 1) (funcall direction rank 1)) (belongs-to-opponent (aref *board* (funcall direction rank 1) (+ file 1)))) (push (cons (+ file 1) (funcall direction rank 1)) movelist)) movelist))