On Wed, Jul 27, 2011 at 10:04 AM, Oskar <oskar.kv...@gmail.com> wrote:
> I have an atom with characters (a map of maps) in my main file. But
> because I don't want to make that file too big I have, for example, a
> file called "ai.clj" with AI stuff, that I require from the main file.
> For the monsters' AI to work, the AI needs to know the state of the
> world, i.e. the characters. My current solution is to (declare
> characters) and then have a
> (defn init-ai [characters] (def characters characters))
> function in ai.clj that I call from the main file at the start of the
> game. It works, but it doesn't feel quite right.

(ns namespace-1 ...)

(def chs (promise))

(defn characters [] (@chs))

...

(ns namespace-2
  (:require namespace-1 :as n1)
  ...)

(defn patrol [...] ...)

(defn predatory-wildlife [...] ...)

(deliver n1/chs
  {
   ...
   {:desc "Dire Wolf" :level 7 :race :canine :ai predatory-wildlife ...}
   {:desc "Dwarven Guard" :level 18 :race :dwarf :ai patrol ...}
   ...})

You'll need to use (characters) or @chs rather than just characters in
namespace-1, though.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to