Commits

Robert Smith committed 85e3a9f

* Extend PERMUTE to allow arbitrary sequence types.
* Extend PERMUTE to allow the return of arbitrary sequence types.

Comments (0)

Files changed (1)

         :when (= i (perm-eval* perm i))
           :collect i))
 
-(defun permute (perm a)
-  "Permute the array A according to PERM."
+(defun permute (perm a &key type)
+  "Permute the sequence A according to PERM. The return an array by
+default unless TYPE is specified."
   (assert (<= (perm-size perm)
               (length a))
           (perm a)
          (result (make-array len)))
     (loop :for i :below len
           :do (setf (aref result i)
-                    (aref a (1- (perm-eval* perm (1+ i)))))
-          :finally (return result))))
+                    (elt a (1- (perm-eval* perm (1+ i)))))
+          :finally (return (if type
+                               (coerce result type)
+                               result)))))
 
 ; HI!!!
 ; HELLO