gpt4 book ai didi

common-lisp - "constant is being redefined"与 defconstant?

转载 作者:行者123 更新时间:2023-12-04 18:03:26 25 4
gpt4 key购买 nike

我正在阅读 PAIP 的第 5.2 章。当我尝试使用完全取自本书的以下形式定义常量时,出现如下所示的错误。我使用 SBCL 1.1.14.debian 作为解释器。我做错了什么?

(defconstant no-bindings '((t . t))
"Indicates pat-match success, with no variables.")

The constant NO-BINDINGS is being redefined (from (T T) to ((T . T)))

最佳答案

该错误意味着您之前定义了同名no-bindings,其值为'(T T)

例如在 REPL 中你做了一个定义:

(defconstant no-bindings '(t  t)
"Indicates pat-match success, with no variables.")

然后您重新定义了 no-bindings :

(defconstant no-bindings '((t . t))
"Indicates pat-match success, with no variables.")

manual指定:

A constant defined by defconstant can be redefined with defconstant. However, the consequences are undefined if an attempt is made to assign a value to the symbol using another operator, or to assign it to a different value using a subsequent defconstant.

已更新

请注意,在 SBCL 中,即使是相同值的双重定义,例如,在 REPL 中写入两次:

(defconstant no-bindings '((t . t))
"Indicates pat-match success, with no variables.")

导致持续的重新定义错误,而在其他系统(我试过 CCL)中,这不会发生。实际上这是由于上述定义中对“不同值”的解释。词汇表说不同的不是相同的,相同的不是 eql,

 (eql '((t . t)) '((t . t)))

给出 NIL,而其他相等运算符,例如:

 (equal '((t . t)) '((t . t)))

返回 T

因此,与其他系统不同,SBCL 似乎正确地遵循了正式规范。

关于common-lisp - "constant is being redefined"与 defconstant?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31283475/

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