On 27.10.2009, at 18:07, Rock wrote:

> these things. Why? Because they're just that: nested vectors. They're
> not truly multidimensional vectors, and the more I think about them,
> the more they really suck from that point of view. For instance, first
> of all they're not that safe to use (for these purposes): you could
> potentially have a RAGGED nested vector, which you might end up
> passing to a function that's expecting a true multidimensional array!

That's indeed one of the arguments against the use of multidimensional  
Java arrays (which are nested arrays) for this purpose.

> What is one to do? Implement checks all over the place just to make
> sure that it's ok? Don't like that.

"All over the place" would be a call to a single test function. But  
this need is not specific to a nested vector representation.  
Basically, there are two approaches to dealing with Clojure data  
structures representing multidimensional arrays:

1) Make them an abstract data structure. Client programs are not  
supposed to know the internal representation, they create arrays  
exclusively by calling factory functions provided for this purpose.  
Functions that expect array arguments can then assume that the data  
structure is consistent and needn't do any checks. The tightness of  
the abstraction can be enforced to various degrees, but that's a  
different issue.

2) Expose the internal representation to client code. Since any  
representation in terms of standard Clojure data structures could be  
invalid, all array functions need to do some check on their arguments.

In fact, the second approach would be the best argument for the use of  
nested vectors, as it is a rather simple and intuitive representation  
from the user's perspective. With the first approach, the internal  
representation would be chosen exlusively for the convenience of the  
implementation.

> But it gets worse. I imagine, when
> dealing with nested vectors, that there's no guarantee that the data
> will be contiguous as when you're dealing with a linear vector. So, as
> far as efficiency is concerned, maybe they're not that good, but I'm
> not sure about that (don't know the implementation details.)

I don't think there is a difference. A Clojure vector is never a  
contiguous block of storage.

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
Note that posts from new members are moderated - please be patient with your 
first post.
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