how do I get a list of it's elements?
I can do:
(map 'list #'(lambda(x)x) a)
but that looks really hokey.
(coerce a 'list)
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
(defun coerce-array-to-list (in-array)
(map 'list
#'identity
(make-array (array-total-size in-array)
:element-type (array-element-type in-array)
:displaced-to in-array)))
CL-USER 6 >
(coerce-array-to-list #2A((1 2 3) (4 5 6) (7 8 9)))
(1 2 3 4 5 6 7 8 9)
clt
> CL-USER 6 >
> (coerce-array-to-list #2A((1 2 3) (4 5 6) (7 8 9)))
> (1 2 3 4 5 6 7 8 9)
Maclisp called this function LISTARRAY.
> (defun coerce-array-to-list (in-array)
> (map 'list
> #'identity
> (make-array (array-total-size in-array)
> :element-type (array-element-type in-array)
> :displaced-to in-array)))
If the OP only needed a function for 1-dimensional arrays, I highly
prefer Barry's solution (use COERCE!), but for a general array, the
following will probably be faster in most implementations, since it
will cons less:
(defun coerce-array-to-list (in-array)
(loop for i below (array-total-size in-array)
collect (row-major-aref in-array i)))
--
(espen)
I'm surprised that someone would write that to return a flat list,
rather than treating the array as a matrix. Ie, I'd have expected:
((1 2 3) (4 5 6) (7 8 9))
I guess that's an argument for keeping it non-standard :-)