On Mar 4, 2009, at 7:50 AM, Konrad Hinsen wrote:

>
> Rich,
>
> is there a reason why metadata is explicitly disabled on function
> objects?
>
> I find myself wanting to put metadata on functions frequently. It
> seems even more important for functions than for anything else, given
> that there is no way to inspect a function object at all, it's a
> complete black box. So I looked at the implementation to see if it
> would be easy to add metadata handling, and found to my surprise that
> function objects already have a metadata pointer but that setting it
> is disabled.
>
> Two situations where I think metadata on functions would be very  
> useful:
>
> - To put on a type tag. If functions are to be first-class data
> objects, it should be possible to have multimethods dispatching on a
> function argument. My concrete use case is stream-generating
> functions with different interfaces that I would like to use with a
> common interface defined as a multimethod.
>
> - For implementing automatic derivatives, it would be useful to
> attach a derivative function to a mathematical function such as log
> or sqrt.
>

It's not because metadata isn't useful for fns. The problem lies with  
the fact that fns are values, so if they support metadata they should  
also support with-meta, i.e. returning a new value with different  
metadata, vs the destructive metadata of reference types (i.e. alter- 
meta!). Supporting with-meta for fns requires they be copyable with  
new metadata (as are all the persistent collections and symbols). I  
haven't decided how best to support that copyability for fns that are  
closures while minimizing the overhead for fns that won't have metadata.

Rich


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

Reply via email to