[Ecls-list] Sequence streams

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sat Aug 27 15:32:26 UTC 2011


 - Implemented SEQUENCE-STREAMs, which are input/output streams defined on
some
   specialized array type. The functions to create them are
     (ext:make-sequence-input-stream vector &key :start :end
:external-format)
     (ext:make-sequence-output-stream vector &key :external-format)
        * If the array is a string, it is a character stream
        * If the array is specialized over integers and EXTERNAL-FORMAT is
NIL
          the stream is a binary stream.
        * Otherwise, it is a binary string but READ/WRITE-CHAR may be used
on it.
   Reading and writing does not preserve the original word size of the array
   but rather threads the array as a collection of bytes (octets), writing
   sequentially over it. Thus, if you use encodings such as UCS2 and UCS4,
make
   sure that you choose the right endianness to match the shape of the
array.

Some examples

> (let ((a (make-array 16 :element-type '(unsigned-byte 8) :initial-element
3 :fill-pointer 0)))
    (with-open-stream (s (ext:make-sequence-output-stream a))
      (write-byte 2 s) (write-byte 3 s))
    a)

#(2 3)
> (let ((a (make-array 16 :element-type '(unsigned-byte 8) :initial-element
3 :fill-pointer 0)))
    (with-open-stream (s (ext:make-sequence-output-stream a :external-format
:utf-8))
      (write-char #\a s) (write-char #\b s) (write-char (code-char 1024) s))
    a)

#(97 98 208 128)
> (let ((a (make-array 16 :element-type '(unsigned-byte 8) :initial-element
97)))
    (with-open-stream (s (ext:make-sequence-input-stream a))
      (read-byte s)))

97
> (let ((a (make-array 16 :element-type '(unsigned-byte 8) :initial-element
97)))
    (with-open-stream (s (ext:make-sequence-input-stream a :external-format
:latin-1))
      (read-char s)))

#\a


-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20110827/7c56f659/attachment.html>


More information about the ecl-devel mailing list