Search code examples
clojurejvmland-of-lisp

Code run in REPL but not if saved to a file


I'm trying to create a text based Clojure game (inspired by 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))

The code is running in the REPL but if I saved the code to a file and trying to run:

(describe-location :attic *nodes*)

I got:

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

What I'm doing wrong?
Here is the file: http://dl.dropbox.com/u/3630641/wizard-game.clj


Solution

  • You have too many parentheses. Instead of (describe-location(:garden *nodes*)), you want (describe-location :garden *nodes*).

    Remember that the name of the function goes after the open paren, not before: you were calling (:garden *nodes*) and then calling describe-location on the result, which failed because describe-location wants two arguments, not one.