变量在 defun 中引用后变为未定义
大家好,stackoverflow 的好心人,我在学习 Adam Peterson 的 Lisp for the Web 教程。有问题的问题可能是 Clozure CL 的问题,但我只是想提供一些背景知识。
发生的事情很简单。我通过 (defvar *games* '()) 声明变量 *games*。当我声明一个引用此变量的函数(例如 game-from-name)时,编译器只会对我大喊未声明的自由变量 *games*。
有谁知道为什么会发生这种情况?
Hello good people of stackoverflow, I am having a weird problem while following Adam Peterson's Lisp for the Web tutorial. The problem in question is probably a problem with Clozure CL, however I just wanted to provide some background.
What's happening is simple. I declare the variable *games* by doing (defvar *games* '()). When I declare a function that references this variable, such as game-from-name, the compiler just yells at me undeclared free variable *games*.
Does anyone know why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在不同的包中执行。尝试在定义和访问变量的位置检查
*in-package*
变量的值,以检查哪个包是最新的。您可以使用in-package
宏来设置当前包。You could be executing in a different package. Try examining the value of the
*in-package*
variable at the points where you define and access the variable to check which package is current. You use thein-package
macro to set the current package.