> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
dunno, I generally don't keep this stuff loaded in my brain, I would
suggest looking at the eval static method in Compiler.java, it has a
boolean parameter for evaling with a new class loader or not, that is
about as far down the path as I recall. What it does, how it does it
it, when it does it, dunno.
You nailed it.
It looks like each top-level form currently gets its own fresh
DynamicClassLoader.
(do
(deftype C [])
(def x1 (C.))
(deftype C [a])
(def x2 (C. 42)))
(.getClassLoader (class x1))
;=> #<DynamicClassLoader clojure.lang.DynamicClassLoader@3e5b38d7>
(.getClassLoader (class x2))
;=> #<DynamicClassLoader clojure.lang.DynamicClassLoader@727f3b8a>
Note the numbers after the @s are different -- each got its own
classloader. This is not exclusive to deftype of course:
(do (def a #()) (def b #()))
(.getClassLoader (class a))
;=> #<DynamicClassLoader clojure.lang.DynamicClassLoader@638bd7f1>
(.getClassLoader (class b))
;=> #<DynamicClassLoader clojure.lang.DynamicClassLoader@581de498>
--Chouser
If you'll pardon a nit-pick, this example is somewhat misleading since
do forms are special-cased by the compiler so that each form they
contain is treated as a top-level form.
Witness:
(do (def a #()) (def b #()))
(= (.getClassLoader (class a)) (.getClassLoader (class b)))
;; => false
;; we can avoid the compiler's special-casing
(when true (def a #()) (def b #()))
(= (.getClassLoader (class a)) (.getClassLoader (class b)))
;; => true
The point you are getting at is correct, but it's better shown without do.
-Phil
Yes, you're right. I shouldn't have used that example without
explaining that. Thanks for doing it for me. :-)
--Chouser