gpt4 book ai didi

lisp - clisp: 变量 x 没有值

转载 作者:太空宇宙 更新时间:2023-11-03 18:50:31 24 4
gpt4 key购买 nike

我在我的 Common Lisp 代码中收到错误 variable MAP has no value(我在 Ubuntu 终端中使用 clisp shell)。我的代码如下所示(*map* 只是一个关联列表,因此您可以跳过它):

(setf *map* '((shore (stars cast reflections on the rippling sea.  
it fills you with a strong but unplaceable emotion.)
(east forest))
(forest (a roof of treetops blots out the sun. something rustles
behind you.)
(west shore)
(north cliff))
(cliff (you nearly stumble into a long and fatal fall into the
sea far below you. you feel a strange urge to throw
yourself off the ledge. it would probably wisest to
leave this place.)
(south forest))))

(defun walk-direction (direction room map)
(second (assoc direction (cddr (assoc room map)))))

(defmacro defspel (&rest rest) `(defmacro ,@rest))

(defspel walk-to (direction room map)
`(walk-direction ',direction ',room map))

(walk-to east shore *map*)

(我正在学习 liserpati 教程,对于那些想知道我可能会犯的任何奇怪行为的人)

如果把walk-to改成

(defspel walk-to (direction room)
`(walk-direction ',direction ',room *map*))

然后一切顺利。然而,这打破了函数式编程的美丽约定,我希望尽可能保持原样——更不用说我仍然不知道为什么我的代码不起作用。

最佳答案

walk-to 的定义在 map 之前缺少一个逗号。看一下输出:

(macroexpand-1 '(walk-to east shore *map*))

关于lisp - clisp: 变量 x 没有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328535/

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