On Fri, Apr 16, 2010 at 12:41 PM, Aravindh Johendran
<[email protected]> wrote:
> Sorry, I shoulda been clearer. By similar functionality, i meant a 20-
> q game with
> 1) the network implemented as closures and
There are various ways you can do this while separating concerns. If
you don't mind specifying the question nodes in
definition-precedes-use order, here is one (untested) way that closely
follows the structure of Graham's code but does not use mutable state:
(defn prompt [s]
(print s)
(flush)
(read))
(defn add-node [nodes node question yes-node no-node]
(assoc nodes node
#((nodes (if (= 'yes (prompt (format "%s\n>> " question)))
yes-node
no-node)))))
((:people (reduce #(apply add-node %1 %2) {} [[:people "Is the person
a man?" :male :female], ...])))
> State is unavoidable in many circumstances I suppose.
Fewer than you would think. Even then, a good design will cleanly
separate the pure from the impure.
-Per
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en