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

Discussion of Common Lisp

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

Postby joeish80829 » Sat May 10, 2014 10:04 am

This is the fastest I have found so far:

Code: Select all
(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
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

Postby marcoxa » Sat May 10, 2014 12:18 pm

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

Cheers
--
MA
Marco Antoniotti
marcoxa
 
Posts: 69
Joined: Thu Aug 14, 2008 6:31 pm

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

Postby joeish80829 » Sat May 10, 2014 1:17 pm

That is great, thanks...what a simple solution
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 4 guests