I found a (supposedly) complete version.. it's really a terrifying thing to behold..
http://www.cliki.net/SHALLOW-COPY-ARRAY
Preserves fill-pointer, element-type, adjustable-p, and displacement..
-vish
On Wed, Mar 10, 2010 at 10:31 PM, doug@hcsw.org wrote:
On Tue, Mar 09, 2010 at 10:12:32PM -0500 or thereabouts, Abram Hindle wrote:
Well if I use copy-seq I get this error from sbcl:
unhandled TYPE-ERROR in thread #<SB-THREAD:THREAD "initial thread" RUNNING {10026F2EC1}>: The value #2A((## ## ## ##) (## #\1 #\ ##) (## ## #\ ##) (## #\ #\ ##) (## #\2 ## ##) (## ## ## ##)) is not of type SEQUENCE.
Ya like I said in my last message that was my mistake. I meant to say vectors are sequences so can be copied with copy-seq. Arrays are not sequences.
(defun copy-array (array) ; (copy-seq array)) (let ((dims (array-dimensions array))) (adjust-array (make-array dims :displaced-to array) dims)))
Where as this does not.
Nice one though it might be a good idea to propagate the element type too so stuff like this doesn't happen:
- (make-array '(2 2) :element-type '(unsigned-byte 8))
#2A((0 0) (0 0))
- (copy-array *)
Error in function MAKE-ARRAY: One can't displace an array of type T into another of type (UNSIGNED-BYTE 8). [Condition of type SIMPLE-ERROR]
I think this is a bit better (but probably still isn't complete because of not copying fill pointers and whatnot):
(defun copy-array (array) (let ((dims (array-dimensions array))) (adjust-array (make-array dims :displaced-to array :element-type (array-element-type array)) dims)))
toronto-lisp mailing list toronto-lisp@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/toronto-lisp