Re: Bug with instance? inside deftypes
Christophe, Is it reasonable to assume that atleast the documentation should be modified to reflect the situation? -- 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
Re: Bug with instance? inside deftypes
To me its an implementation wart which is dictated by the use of the reflection API in the compiler. There is some work done by Stu to create a clojure reflection API with several backends (eg ASM or Java Reflection). However I won't bet on the *current* compiler being fixed. my 2 cents Christophe On Thu, Nov 4, 2010 at 4:09 AM, ka wrote: > >> I would guess the problem is referring to T inside the deftype. > > This also works: > > (deftype T [] Object (equals [this o] (if (= T (class o)) true > false))) > > But as Meikel said hope that this is not the end of the story. > > -- > 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 > -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) -- 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
Re: Bug with instance? inside deftypes
>> I would guess the problem is referring to T inside the deftype. This also works: (deftype T [] Object (equals [this o] (if (= T (class o)) true false))) But as Meikel said hope that this is not the end of the story. -- 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
Re: Bug with instance? inside deftypes
Hi, On 3 Nov., 14:58, Adrian Cuthbertson wrote: > I would guess the problem is referring to T inside the deftype. This works; > > (deftype T [] Object (equals [this o] (if (instance? (class this) o) > true false))) > (let [t (T.)] (.equals t t)) > ==> true I hope that this is not the end of the story. :/ Sincerely Meikel -- 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
Re: Bug with instance? inside deftypes
I would guess the problem is referring to T inside the deftype. This works; (deftype T [] Object (equals [this o] (if (instance? (class this) o) true false))) (let [t (T.)] (.equals t t)) ==> true On Wed, Nov 3, 2010 at 12:39 PM, ka wrote: > Clojure 1.2.0 > 1:1 user=> > 1:2 user=> > 1:3 user=> (deftype T [] Object (equals [this o] (if (instance? T o) > true false))) > user.T > 1:4 user=> (def t (T.)) > #'user/t > 1:5 user=> (.equals t t) > false > 1:6 user=> (deftype T [] Object (equals [this o] (if (= T (class o)) > true false))) > user.T > 1:7 user=> (def t (T.)) > #'user/t > 1:8 user=> (.equals t t) > true > 1:9 user=> > > (doc deftype) especially says: >> In the method bodies, the (unqualified) name can be used to name the class >> (for calls to new, instance? etc). > > Somebody on the IRC pointed out: >>> while compiling the deftype, T resolves to a different class object (a >>> compiler-generated stub class) which might conflict with the special >>> inlining of instance? > > Thanks > > -- -- 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
Bug with instance? inside deftypes
Clojure 1.2.0 1:1 user=> 1:2 user=> 1:3 user=> (deftype T [] Object (equals [this o] (if (instance? T o) true false))) user.T 1:4 user=> (def t (T.)) #'user/t 1:5 user=> (.equals t t) false 1:6 user=> (deftype T [] Object (equals [this o] (if (= T (class o)) true false))) user.T 1:7 user=> (def t (T.)) #'user/t 1:8 user=> (.equals t t) true 1:9 user=> (doc deftype) especially says: > In the method bodies, the (unqualified) name can be used to name the class > (for calls to new, instance? etc). Somebody on the IRC pointed out: >> while compiling the deftype, T resolves to a different class object (a >> compiler-generated stub class) which might conflict with the special >> inlining of instance? Thanks -- 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