Re: Road to Clojure Survey
- From: Scott <xscottg@xxxxxxxxx>
- Date: Mon, 23 Feb 2009 15:41:36 -0800 (PST)
On Feb 23, 9:53 am, Alessio Stalla <alessiosta...@xxxxxxxxx> wrote:
Sorry for stepping into this discussion from nowhere,
That's how we all got here. :-)
but I'd like to point out that, although the general contract
for Java collections requires providing an initializing
constructor taking another Collection as a parameter, AFAIK
such a constructor is generally implemented using the addAll()
method (see for example
http://kickjava.com/src/java/util/ArrayList.java.htm
), so Pascal's statement (that some widely used operations
on Java collections require mutation) is not wrong in principle.
I don't think Pascal was complaining about the internal implementation
details of the constructors. I think he was saying that the
interfaces required him to create an empty object and then add all the
items directly. Please see the text I quoted, or Pascal's original
messages, if you disagree with me.
OTOH I suspect that
Clojure's collections will provide that very same constructor
implemented using non-mutating operations.
Someone's got to build it up piece by piece somewhere, but that's an
implementation detail, not an interface one.
Collections.sort(...) won't work on Clojure's immutable collections.
It should throw an UnsupportedOperationException - exactly as it is
documented to do in this case.
Also, while it's true that mutating operations are "optional", in
practice common use of collections in Java involves mutating them.
Immutable collections are not idiomatic (they're not idiomatic in
Common Lisp either, for that matter, even if in general Common Lisp
favours a more "functional" use of sequences/collections).
Without some pretty ugly hackery, algorithms can't mutate a collection
instance that doesn't want to be mutated. Even though common Java
idiom is to implement mutable objects, the JDK Collection interfaces
and algorithms explicitly allow immutable ones, and the JVM will
enforce that immutability to a degree beyond most other programming
environments.
So, as always truth lays in the middle :)
I'm not sure if you're just trying to keep the peace, but I don't
think it lies that close to center in this case. Pascal's a smart
guy, but I think he misremembered a few things. Maybe he's recalling
JDK 1.1 - that was before the Collection interfaces were defined. The
Java implementers possibly introduced the Collection APIs to deal with
exactly the sorts of problems that Pascal was unhappy about.
That said, having Clojure's collections follow the Java
Collections interfaces is certainly a Good Thing, even
if one admits they're not "seamlessly integrated" with
the collections framework.
"Seamlessly" is a pretty subjective word. However, given the
constraints, I'm not sure how you'd go about making it any more
seamless than it is.
Cheers,
-Scott
.
- References:
- Road to Clojure Survey
- From: Kenneth Tilton
- Re: Road to Clojure Survey
- From: Rich Hickey
- Re: Road to Clojure Survey
- From: duane
- Re: Road to Clojure Survey
- From: Rich Hickey
- Re: Road to Clojure Survey
- From: Pascal Costanza
- Re: Road to Clojure Survey
- From: Rich Hickey
- Re: Road to Clojure Survey
- From: Pascal Costanza
- Re: Road to Clojure Survey
- From: Rich Hickey
- Re: Road to Clojure Survey
- From: Pascal Costanza
- Re: Road to Clojure Survey
- From: AndyF
- Re: Road to Clojure Survey
- From: Pascal Costanza
- Re: Road to Clojure Survey
- From: Scott
- Re: Road to Clojure Survey
- From: Pascal Costanza
- Re: Road to Clojure Survey
- From: Scott
- Re: Road to Clojure Survey
- From: Alessio Stalla
- Road to Clojure Survey
- Prev by Date: Re: Road to Special Enlightenment Survey
- Next by Date: Re: Lexical and dynamic scope example?
- Previous by thread: Re: Road to Clojure Survey
- Next by thread: Re: Road to Clojure Survey
- Index(es):
Relevant Pages
|