common-lisp - 为什么 SBCL 抱怨 setf?
问题描述
在 SBCL 中,这将分配'bar
给foo
,并带有警告:
* (setf foo 'bar)
; in: SETF FOO
; (SETF FOO 'BAR)
; ==>
; (SETQ FOO 'BAR)
;
; caught WARNING:
; undefined variable: COMMON-LISP-USER::FOO
;
; compilation unit finished
; Undefined variable:
; FOO
; caught 1 WARNING condition
BAR
*
以下来自图雷茨基。我将其输入“7.29.lisp”并保存。
(setf database
’((b1 shape brick)
(b1 color green)
(b1 size small)
(b1 supported-by b2)
(b1 supported-by b3)
(b2 shape brick)
(b2 color red)
(b2 size small)
(b2 supports b1)
(b2 left-of b3)
(b3 shape brick)
(b3 color red)
(b3 size small)
(b3 supports b1)
(b3 right-of b2)
(b4 shape pyramid)
(b4 color blue)
(b4 size large)
(b4 supported-by b5)
(b5 shape cube)
(b5 color green)
(b5 size large)
(b5 supports b4)
(b6 shape brick)
(b6 color purple)
(b6 size large)))
于是:
* (load "7.29.lisp")
While evaluating the form starting at line 1, column 0
of #P"/home/redacted/7.29.lisp":
debugger invoked on a SIMPLE-ERROR in thread
#<THREAD "main thread" RUNNING {10005D05B3}>:
odd number of args to SETF: (SETF DATABASE ’
((B1 SHAPE BRICK) (B1 COLOR GREEN)
(B1 SIZE SMALL) (B1 SUPPORTED-BY B2)
(B1 SUPPORTED-BY B3) (B2 SHAPE BRICK)
(B2 COLOR RED) (B2 SIZE SMALL)
(B2 SUPPORTS B1) (B2 LEFT-OF B3)
(B3 SHAPE BRICK) (B3 COLOR RED) ...))
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [RETRY ] Retry EVAL of current toplevel form.
1: [CONTINUE] Ignore error and continue loading file "/home/redacted/7.29.lisp".
2: [ABORT ] Abort loading file "/home/redacted/7.29.lisp".
3: Exit debugger, returning to top level.
(SB-C::EXPLODE-SETQ (SETF DATABASE ’ ((B1 SHAPE BRICK) (B1 COLOR GREEN) (B1 SIZE SMALL) (B1 SUPPORTED-BY B2) (B1 SUPPORTED-BY B3) (B2 SHAPE BRICK) (B2 COLOR RED) (B2 SIZE SMALL) (B2 SUPPORTS B1) (B2 LEFT-OF B3) (B3 SHAPE BRICK) (B3 COLOR RED) ...)) ERROR)
0]
为了让 SBCL 对这些作业感到满意,我需要了解什么?
解决方案
推荐阅读
- javascript - 为什么参数通过闭包无效?
- arrays - 循环遍历数组以在另一个数组中查找匹配值时,如何优化流控制?
- javascript - 如何使用 Bolt for JavaScript(Node.JS) 获取 Slack 机器人的当前用户电子邮件地址
- node.js - 在哪里找到关系多对多 TypeOrm?
- angular - 如何监听 Firebase 中众多子集合的变化
- c++ - 机器上给定双精度值的最大精度可表示值是多少?
- javascript - javascript if 然后加载 ajax 和输入计数
- php - $.ajax 仅在 safari 中获得 419,适用于 chrome 和 FF
- python - 如何为 Pydantic/FastAPI 的枚举类设置默认值
- python - pyngrok - 重试失败的连接