clojure - 代码在 REPL 中运行,但如果保存到文件则不会

标签 clojure jvm land-of-lisp

我正在尝试创建一个基于文本的 Clojure 游戏(灵感来自 Land of Lisp)。

(def *nodes* {:living-room "you are in the living-room. a wizard is snoring loudly on the couch."
              :garden "you are in a beautiful garden. there is a well in front of you."
              :attic "you are in the attic. there is a giant welding torch in the corner."})

(defn describe-location [location nodes]
    (nodes location))

代码在 REPL 中运行,但如果我将代码保存到文件并尝试运行:

(describe-location :attic *nodes*)

我得到了:

Exception in thread "main" java.lang.IllegalArgumentException: Wrong number of args (1) passed to: user$describe-location (wizard-game.clj: 0)

我做错了什么?
这是文件:http://dl.dropbox.com/u/3630641/wizard-game.clj

最佳答案

你的括号太多了。您需要 (describe-location :garden *nodes*) 而不是 (describe-location(:garden *nodes*))

请记住,函数的名称在开括号之后,而不是之前:您正在调用 (:garden *nodes*) 然后调用 describe -location 结果失败,因为 describe-location 需要两个参数,而不是一个。

关于clojure - 代码在 REPL 中运行,但如果保存到文件则不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5200169/

相关文章:

macros - 在 clojure 中评估宏参数

overflow - Wumpus游戏的make-city-edges函数导致堆溢出

haskell - 如何从功能上计算未知大小列表的连续元素之间的差异?

java - 创建 Lambda 函数实例

在 EC2 上进行 Jetty 冒烟测试后,Java 虚拟机变得无响应,一个核心 100%

lisp - Lisp 中的内存分配

clojure - 为什么 Java 会提示找不到命名空间?

java - Clojure GUI 计算器。 "-"总是返回 0 而 "/"总是返回 1

clojure - 如何验证环应用中的路由子集?

android - 无法识别的 VM 选项 'MaxPermSize=512m' 错误 : Could not create the Java Virtual Machine. 错误 : A fatal exception has occurred. 程序将退出