Hello everyone, 
I have a ref, which is a hashmap of monsters (they key is a unique id, the 
value is the monster) like this:

*(defrecord mob [name level hp-cur hp-max])
(def mobs (ref {}))
(defn addmob []
  (dosync (alter mobs assoc (gen-id) (->mob "test" 1 2 3)))*

Now if I add 1000 monsters, like this:
*(repeatedly 1000 addmob)*
it will take a few minutes, use a lot of RAM and might even fail if its not 
a 64 bit JRE (due to RAM limitations).

As it seems the problem isn't exactly clojure, its the fact that the result 
is being shown in the REPL (which is a huge string).

If I modify my addmob function to return nil:
*(defn addmob []
  (dosync (alter mobs assoc (gen-id) (->mob "test" 1 2 3))
  nil)
*Then *(repeatedly 1000 addmob)* is really fast because it doesn't show the 
whole result in the REPL.

*(Please note that the problem has nothing to do with the repeatedly 
function. Even if I already have 1000 mobs in my hashmap and then only add 
another one, it also takes forever to show the result in the REPL.)*


Does anyone know a elegant solution to my problem, besides writing 
something like "alter-silent" that always returns nil instead of the whole 
ref? Am I just using things the wrong way? Or could it have something to do 
with Eclipse?

Thanks in advance!

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to