On Thu, Jul 9, 2009 at 4:19 PM, Richard Newman<[email protected]> wrote:
>
> Is there any particular reason why Fn doesn't implement IMeta?

Actually, it does.

user=> (instance? clojure.lang.IMeta (fn []))
true

What it doesn't support is changing the metadata after
creation:

user=> (with-meta (fn []) {:foo "bar"})
java.lang.UnsupportedOperationException (NO_SOURCE_FILE:0)

The reasons for this have to do with difficulties involved
in cloning a closure as would be necessary.

You can however set the metadata when you create a new
instance -- AFn takes a metadata map in its constructor.
There's no syntax supporting it directly, but you can get at
it from Java, gen-class, or proxy:

(def add
  (proxy [clojure.lang.AFn] [{:i-has "metadata!"}]
    (invoke [a b] (+ a b))))

user=> (add 2 5)
7
user=> ^add
{:i-has "metadata!"}

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to