Is there any "easy way" to get ((1 2) (3 4)) from #((1 2) (3 4))?
Thanks in advance.

Actually, #((1 2) (3 4)) is a vector of two elements, both of which are lists, so you can:Ferreira wrote:Is there any "easy way" to get ((1 2) (3 4)) from #((1 2) (3 4))?
Code: Select all
[1]> #((1 2)(3 4))
#((1 2) (3 4))
[2]> (coerce #((1 2)(3 4)) 'list)
((1 2) (3 4))
Code: Select all
(defun to-list (2d-array)
(loop for i from 0 below (array-dimension 2d-array 0)
collect (loop for j from 0 below (array-dimension 2d-array 1)
collect (aref 2d-array i j))))
CL-USER> (to-list #2A((1 2)(3 4)))
((1 2) (3 4))
You can use :initial-contents keyword argument for make-array:Ferreira wrote:I know I can use the coerce function to make a list from a given array, However, when I give it a multidimensional array I get a list of all elements.
Is there any "easy way" to get ((1 2) (3 4)) from #((1 2) (3 4))?
Thanks in advance.
Code: Select all
(make-array '(2 2) :initial-contents '((1 2) (3 4)))
=>
#2A((1 2) (3 4))