On 27.04.2009, at 00:33, David Chamberlin wrote: > I can get round this by not using a structure map for the metadata, > but since I'm going to be creating container loads of these structures > I understand that I need to be using struct-maps for efficiency. > > Is there a reason why this should not work?
Here is why it does not work. Any attempt to print a value causes a call to clojure.core/print-method. This is a multimethod that dispatches on clojure.core/type, i.e. by the :type on the metadata or, if there is no metadata or no :type tag, on class. If there is a :type tag but it has no implementation of print-method, a :default implementation removes the :type tag and tries again. It's removing the type tag that fails in your case. On March 27 I sent a message to this group that contains a patch for clojure.core that fixes this problem, and other of a similar kind. The subject is "PATCH: printing a ref with type metadata". I can't find the message in Google's archive, so I wonder if it got lost. The patch is attached again to this message. As for efficiency, I doubt that struct maps make that much of a difference, but I didn't do any timings. Note that in your example, you create the metadata map once and assign it to m. The map is thus created only once, no matter to how many values you attach it later. That's how I handle metadata maps as well. The only potential difference in execution time thus comes from looking up :type. Compared to the rest of the work done in multimethod dispatching, I can't imagine that key lookup is that much more efficient for struct maps that it makes a difference overall. 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 -~----------~----~----~----~------~----~------~--~---
print-method.patch
Description: Binary data