>> 3. I think it would be great to have better support for circular
>> references - perhaps a two-pass compile? The reason this is
>> particularly acute in game development is that different subsystems
>> have quite a lot of inter-dependencies. AI evaluation system needs to
>> understand game state/engine so it can evaluate a position. Game state/
>> engine needs to understand units so it can manipulate them. Units need
>> to understand AI evaluation system so they can decide which actions to
>> take...... obviously it's possible to work around all this, but it's a
>> major pain, adds complexity and means that you need to structure code
>> to manage dependencies rather than in logical modules (which would be
>> easier to manage and maintain!)
>
> I'm not sure what you mean by this, can you expand on this?

Though I didn't write that paragraph, I have faced the same issue.

Suppose I have two functions in the same file, and one depends on the other:

   (defn foo [x] (+ 1 x))
   (defn bar [x] (* 2 (foo x)))

I can't switch their order without adding extra forward-declaration
code, which is redundant:

   (declare foo)
   (defn bar [x] (* 2 (foo x)))
   (defn foo [x] (+ 1 x))

This example is just a minor irritation, that I need to make sure all
the functions in a file are in the right order.

A bigger problem is when the two functions are in different
files/packages. Suppose I have files a.clj and b.clj and place some of
my functions in each of those files based on some arbitrary
categorization that makes intuitive sense to me. Then I realize that
some of the functions in a.clj depend on some functions in b.clj,
while some functions in b.clj depend on some functions in a.clj. Can I
still use declare to resolve this circular dependency? Can I even
"require" a.clj from b.clj when I have already "require"d b.clj from
a.clj?

My solution so far has been to make sure that dependencies between
packages are never two-way. I deliberately choose categorizations that
won't result in circular dependencies between packages. I would much
prefer to just refer to whatever function I wish, from whichever
function I wish, and not need to think about which packages I am
allowed to depend on or in what order functions must appear in a file.

-- 
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