On 01.01.2010, at 23:56, Hugo Duncan wrote:
>> I want to create a new instance of a deftype from inside one of its
>> methods.
>
> I ended-up using extend-type for this case.
That's probably the cleanest solution, but you lose the performance
benefit of defining methods right in the type definition.
After looking at the deftype code, I came up with the following
solution:
(defprotocol Foo
(foo [x]))
(deftype Bar
[i]
Foo
(foo [] (new Bar (inc i))))
(foo (Bar 0))
Its drawback is relying on an undocumented feature: the value of Foo
inside the methods is the class Foo being defined.
Konrad.
--
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