On 29.10.2009, at 14:01, Rock wrote:

>>> Suppose we're dealing with rank n objects. Do you think it
>>> would be an easy task to figure all that out dealing with nested
>>> vectors?
>>
>> If you can assume the array is well-formed, it is rather easy.
>> Otherwise it isn't.
>
> Can you give an example in code? I really would like to see it.

(defn rank
   [item]
   (if (vector? item)
       (inc (rank (nth item 0)))
       0))

(rank 0)
(rank [1 2 3])
(rank [[1 2] [3 4]])

(defn shape
   [item]
   (if (vector? item)
     (let [element (nth item 0)
          n       (count item)]
       (cons n (shape element)))
     (list)))

(shape 0)
(shape [1 2 3])
(shape [[1 2] [3 4]])

>>> And by the way, How would you go about implementing in detail
>>> a check to see if a nested vector is actually an authentic
>>> multidimensional array or not?
>>
>> That's a rather simple recursive function. The only problem is its  
>> run-
>> time cost.
>
> Please provide an example. In the meantime, I'll give it a shot
> myself.

(defn check-multiarray
   [item]
   (and (vector? item)
        (apply = (map shape item))))

; true
(check-multiarray [1 2 3])
(check-multiarray [[1 2] [3 4]])
; false
(check-multiarray 1)
(check-multiarray [[1 2] 3])
(check-multiarray [[1 2] [3]])

> I feel Clojure can and actually should become a language well-suited
> for scientific computation. It may not have all the prerequisites now,
> but, hey, this is Lisp, and it can be done, always! :)

I completely agree. I don't think Clojure will become a mainstream  
language for science any time soon, for that it is too "exotic" for a  
community that still sticks to Fortran. But it can find its niche, and  
perhaps not even a small one.

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