On Nov 6, 7:50 am, mb <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On 6 Nov., 13:30, Chanwoo Yoo <[EMAIL PROTECTED]> wrote:
>
> > > Is {:a 1} not a hash-map? It seems that there is some inconsistency...
>
> Clojure holds promises about the interface and the performance
> characteristics of the provided functions. In general Clojure is
> a lot about abstract interfaces. The underlying thing may change
> as necessary to provide the best implementation for the specific
> case.
>
> An array map may be good for maps with a very small number of
> entries, but inappropriate for maps with a big number of entries.
> Since Clojure only promises the interface, it's free to decide
> that assoc should now return a converted map for performance
> reasons.
>
> At least this is the impression I got from Rich's talk at - I think -
> the Boston Lisp Group. I think he mentioned something like this.
> Please correct me if I'm wrong.
>
You are right - this is the correct answer to the question.
Clojure is about programming to abstractions, among other things. So
you don't want to rely on the exact concrete types of things, but
rather the interfaces they implement.
There are many useful interfaces in Clojure. Chouser put together a
nice visualization:
http://clojure.googlegroups.com/web/chart.png
If you use class as a dispatch function in a multimethod, you can use
an interface, like IPersistentMap, as a dispatch value and it will
match all classes that extend IPersistentMap, since multimethod
dispatch uses isa?
There are also predicates that correspond to most of the interfaces,
like map?, list?, vector?, sorted? etc, all of which internally use
(instance? someInterface x). The aforementioned chart includes the
corresponding predicates.
In general, it is bad style to use class equality, as in (= (class
this) (class that)) - better to use instance? or isa?.
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 [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---