This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

What is the fastest way to convert a Lisp vector to a list

3 posts · 3682 views

This is the fastest I have found so far:
(defun array-to-list (array)
  (let* ((dimensions (array-dimensions array))
         (depth      (1- (length dimensions)))
         (indices    (make-list (1+ depth) :initial-element 0)))
    (labels ((recurse (n)
               (loop for j below (nth n dimensions)
                     do (setf (nth n indices) j)
                     collect (if (= n depth)
                                 (apply #'aref array indices)
                               (recurse (1+ n))))))
      (recurse 0))))
Can anyone show me how to do this extremely fast. It would be a n length vector...unlimited elements

Re: What is the fastest way to convert a Lisp vector to a li

I would just use COERCE. But then.... why do you need this? I presume not for performance....

Cheers
--
MA
Marco Antoniotti

Re: What is the fastest way to convert a Lisp vector to a li

That is great, thanks...what a simple solution