Subject: Re: Interesting type issue (a.k.a. breaking your programs using specialised arrays and print/read)
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 14 Dec 2003 04:49:16 -0600
Newsgroups: comp.lang.lisp
Message-ID: <8vecnWotBoKx3UGiXTWc-w@speakeasy.net>
Adam Warner  <usenet@consulting.net.nz> wrote:
+---------------
| Hi Rob Warnock,
| > Well, what about this, then?
| > 
| > 	> (make-array 10 :element-type 'double-float
| > 	    :initial-contents '(0d0 1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0 9d0))
| > 
| > 	#(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0)
| > 	> (type-of *) 
| > 
| > 	(SIMPLE-ARRAY DOUBLE-FLOAT (10))
| > 	> 
| 
| What's your point Rob? (Mine was that the semantics of readable printed
| objects broke because Common Lisp doesn't print and read back in the type
| of the array along with the array contents)
+---------------

And mine was only that there is a simple workaround for the problem you
presented that is less painful than looping over a setf/aref, namely,
passing the vector you got from READ to MAKE-ARRAY's :INITIAL-CONTENTS.

Though I apologize for not making it clear in my example that
:INITIAL-CONTENTS can take a sequence, not just a list, and that
the :ELEMENT-TYPE could be picked out of the read-in array, but
you already knew all that, yes?

	> (read-from-string "#(0d0 1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0 9d0)")
	#(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0)
	> (type-of *)

	(SIMPLE-VECTOR 10)
	> (make-array 10 :element-type (type-of (aref ** 0))
			 :initial-contents **)

	#(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0)
	> (type-of *)

	(SIMPLE-ARRAY DOUBLE-FLOAT (10))
	> 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607