Re: Is this a bug in 'read-vector?

Raymond Toy <[email protected]>
Newsgroups gmane.lisp.cmucl.general
Message-ID <[email protected]>
>>>>> "Jeffrey" == Jeffrey Cunningham <[email protected]> writes:

    Jeffrey> I have been trying to read large binary files of floating point data
    Jeffrey> using CMUCL (19c). I thought I would have to do it using some form of
    Jeffrey> FFI and went to comp.lang.lisp for help getting that working. I
    Jeffrey> succeeded. But Duane Rettig at Allegro suggested it would be easier to
    Jeffrey> use 'read-vector. So I tried that as follows:

    Jeffrey> (let ((vec (make-array 10 :element-type 'double-float)))
    Jeffrey>   (with-open-file (os "d10.bin")
    Jeffrey>     (read-vector vec os)
    Jeffrey>     (print vec)))

    Jeffrey> where "d10.bin" is a double-float binary file containing 10
    Jeffrey> elements. When I try to read the file it produces the following error:

    Jeffrey> Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
    Jeffrey>    #\Null is not of type DOUBLE-FLOAT

[snip]

    Jeffrey> Is this really a bug? Or am I doing something else wrong?

Yes, this does appear to be a bug in the implementation of
read-vector.

You can, however, achieve what you want by opening the file with an
element-type of, say, (unsigned-byte 8), instead of the default
'character.

I'll have to read some more to understand how read-vector interacts
with the stream element type.  It seems, though, that the element-type
of the vector overrides the element-type of the stream, more or less.
Currently, a stream element type of character basically causes the
code to read in characters.

Ray
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.