On 24.05.2009, at 07:01, Feng wrote:

> clojure.contrib.types/deftype assumes data to tag are created fresh
> with no meta data. Would it be useful to have it update meta data if
> data are already initialized with meta data, e.g. from file or db with
> other meta data, but :type ::constructor are too program specific to
> be stored in there?

I considered this, but decided to postpone any action until the  
problem actually occurs. The reason why I prefer the current approach  
wherever it is applicable (i.e. for any values that don't need  
metadata other than for type identification is the associated overhead.

My current implementation creates a single metadata map per type that  
is then attached to each data item. The memory overhead is  
negligible, and the CPU time overhead is just one call to with-meta  
per object creation. The modification that you propose (as well as  
the variant I had considered, using vary-meta) creates a metadata map  
per object, resulting in potentially lots of metadata maps, even  
though many could be identical, and requiring map operations of non- 
negligible cost for each object creation.

Several solutions are envisageble:

1) Check if the object has metadata, and put on a predefined map if  
not. This leads to an increased CPU overhead for each object  
creation, to to a memory overhead only for types that actually  
require it.

2) Make the metadata handling an option specified by a parameter to  
deftype.

3) Delegate metadata handling to the constructor, at least optionally.

It's hard to choose among these solutions without having some real- 
life use cases.

Konrad.


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