> You could also use reify:
>
> (defn make-foo [s]
> (reify clojure.lang.IFn
> (invoke [this] (str "Hello, " s))))
>
> ((make-foo "RJ"))
> "Hello, RJ"
>
> I have to admit, though, that I'm unclear on the relative merits of defrecord
> vs. reify. Anyone want to comment?
>
> Cheers,
> -Michael Nygard
defrecord gives you a lot of stuff, even before you start to add interfaces /
protocols:
(defrecord Foo [a])
(ancestors Foo)
=> #{clojure.lang.IPersistentCollection clojure.lang.Seqable
clojure.lang.ILookup clojure.lang.Associative clojure.lang.IKeywordLookup
java.util.Map clojure.lang.IPersistentMap clojure.lang.IObj
clojure.lang.Counted clojure.lang.IMeta java.lang.Object java.io.Serializable
java.lang.Iterable}
If you need some of that stuff, defrecord is more appropriate. If you need only
a named class + IFn, use deftype. If you need only IFn, use reify.
Stu
Stuart Halloway
Clojure/core
http://clojure.com
--
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