我正在尝试创建一个基于文本的 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/