On Mar 12, 2009, at 10:59, Jeff Rose wrote:

>> My main conclusion is that Clojure's system is a lot more flexible
>> but also a lot more fragile. Any function can modify data of any
>> "type" (as defined by metadata), even without being aware of this.
>
> Modifying type tags without being aware of it?

Not modifying type tags, but modifying data that has a type tag  
without being aware of the fact that the data has a type tag, and  
thus perhaps specific constraints on its contents. The most basic  
example is calling dissoc on a map to remove a key that is required  
by the semantics of the type implemented as a map. dissoc is agnostic  
about type tags, so it won't complain.

In this specific case, struct maps can be used to prevent a key from  
being removed, but that's a solution only for this specific case, and  
not necessarily a simple one to implement.

> We've heard this line of reasoning before when moving from static to
> dynamic languages.  If having the power to do what you want with the
> language scares you, then maybe Java is a better choice.  All these

It doesn't scare me, otherwise I wouldn't be using Clojure. And I  
wouldn't be using Python as my main language either. However, I think  
it is important to be aware of the risks in order to watch out for them.

> Adding an implementation for a new type to a multimethod is equivalent
> to adding an interface implementing method to a class you defined.  So
> for example you could add to-string or to-xml or to-bytes or  
> whatever to
> your own objects to make them interoperate with some existing library.
> Having libraries built on top of abstract interfaces like this is
> exactly what makes them interesting.

I agree, of course. And yet, it is important to be aware of the  
consequences. For example, don't ever try to memoize the dispatching  
function of a multimethod - its result may well change after  
importing another library module.

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