gpt4 book ai didi

variables - 无法在本地声明常量变量 在 Ubuntu Trusty Tahr 上安装人工智能现代方法代码时出错 - Common Lisp

转载 作者:行者123 更新时间:2023-12-04 19:20:13 27 4
gpt4 key购买 nike

我正在安装我在这里得到的《人工智能一种现代方法》一书的代码 http://aima.cs.berkeley.edu/lisp/doc/install.html它的 lisp 版本我正在安装 btw

我在 Ubuntu Trusty 上使用 Emacs SBCL slime,我将代码放在 ~/.emacs.d

所以按照上面链接的说明我运行(加载“/home/w/.emacs.d/aima/code/aima.lisp”)

加载很好我得到“T”作为输出

我运行(aima-load 'all)有效我得到“T”作为输出

但是当我运行(aima-compile)时,我得到了错误

Can't declare constant variable locally special: +NO-BINDINGS+
[Condition of type SIMPLE-ERROR]

我不确定我是否理解我在 Declare 和 Special 上阅读 Hyperspec 的错误,但这并没有帮助。我不反对 hack 来完成这项工作,所以如果有人可以帮助我改写代码或弄清楚它是 emacs 设置还是 sbcl 设置,我可以更改以声明上述变量,这将是很棒的。错误消息是指此文件/home/w/.emacs.d/aima/code/logic/algorithms/tell-ask.lisp

本节
(defmethod ask-each ((kb literal-kb) query fn)
"For each proof of query, call fn on the substitution that
the proof ends up with."
(declare (special +no-bindings+))
(for each s in (literal-kb-sentences kb) do
(when (equal s query) (funcall fn +no-bindings+))))

我验证了我的 aima 文件夹中所有文件的所有权限都设置为我的用户名的读写权限,我的用户名作为所有者作为更正的步骤....但就理解错误而言,我可以使用帮助找出下一个第一步需要调试...代码可在此处下载 http://aima.cs.berkeley.edu/lisp/code.tar.gz对于资深的 emacs/lisp 用户来说,它的安装很容易......任何帮助表示赞赏。

最佳答案

使用 SBCL:
我也尝试加载 AIMA 代码,但在 SBCL 中遇到了同样的问题。只需将 ./logic/algorithms/tell-ask.lisp 中的行注释掉即可:

(declare (special +no-bindings+))
像这样
;;(declare (special +no-bindings+))
,或完全删除整行。尽管如此,这就是我所做的:
(defmethod ask-each ((kb literal-kb) query fn)
"For each proof of query, call fn on the substitution that
the proof ends up with."
;;(declare (special +no-bindings+))
(for each s in (literal-kb-sentences kb) do
(when (equal s query) (funcall fn +no-bindings+))))
您仍然会遇到运行 (aims-compile) 的问题与 SBCL。它会提示一些常量被重新定义。只需查看可能的重新启动并选择每次:
0: [CONTINUE] GO ahead and change the value.
根据需要多次(大约 6 次)执行此操作,最终会加载。这可能是因为 AIMA 的代码非标准构建/编译系统。这可能很烦人,但另一种方法是跟踪代码并查看重新加载某些文件的原因/位置。
使用 Clozure (CCL):
CCL 与 ./utilities/utilities.lisp 有不同的问题. CCL有 truefalse功能预定义,因此您必须确保这两行:
#-(or MCL Lispworks)
直接在 (defun true ...) 之前和 (defun false ...)改为:
#-(or MCL Lispworks CCL)
此外,在同一来源中,修改 error里面 for-each宏看起来像这样:
(error "~a is an illegal variable in (for each ~a in ~a ...)"
var var list)
通过这些修改,CCL 似乎可以很好地加载 AIMA 代码。
一般来说:
重新定义常量或以某种方式绕过调试器重新启动是一个坏主意。最好的解决方案是拥有 (defconstant ...) s 只评估一次,可能通过将它们放在一个单独的源文件中并确保构建系统只选择一次。
找到另一个解决方案 here ,这需要包装对 defconstant 的调用在这样的宏中(借自 here ):
(defmacro define-constant (name value &optional doc)
(if (boundp name)
(format t
"~&already defined ~A~%old value ~s~%attempted value ~s~%"
name (symbol-value name) value))
`(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
,@(when doc (list doc))))
然后替换所有出现的 defconstant像这样:
(defconstant +no-bindings+ '((nil))
"Indicates unification success, with no variables.")
和:
(define-constant +no-bindings+ '((nil))
"Indicates unification success, with no variables.")
如果您选择 define-constant “解决方案”,确保 define-constant首先被评估。

关于variables - 无法在本地声明常量变量 在 Ubuntu Trusty Tahr 上安装人工智能现代方法代码时出错 - Common Lisp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22264775/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com