[Openmcl-devel] Bivalent file stream? (Zach Beane)

Shannon Spires svs at bearlanding.com
Thu Nov 17 10:40:21 PST 2016


On Nov 10, 2016, at 4:00 AM, Zach Beane <xach at xach.com> wrote:

> 
> Is there an easy way to create a bivalent stream to output to a file?
> 
> If there isn't an easy way, what's the least worst way?
> 
> Thanks,
> Zach

Here's one way:

(defun enable-char-output (stream)
  "Call this to enable character output to a binary stream in CCL."
  (let ((ioblock (ccl::basic-stream-ioblock stream)))
    (setf (ccl::ioblock-write-char-function ioblock) 'ccl::%ioblock-write-u8-encoded-char
          (ccl::ioblock-write-simple-string-function ioblock) 'ccl::%ioblock-write-u8-encoded-simple-string)))

(defun test-bivalent (&optional (path #P"ccl:bivalent.txt"))
  (with-open-file (stream path :direction :output :if-exists :supersede
                          :sharing nil
                          :element-type '(UNSIGNED-BYTE 8))
    ; make it possible for CCL to write characters to binary streams
    (enable-char-output stream)
    (write-sequence "STRING TEST" stream)
    (write-char #\x stream)
    (write-byte #x20 stream)
    (write-byte #x0D stream)
    (write-byte #x0A stream)))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20161117/c8438096/attachment.htm>


More information about the Openmcl-devel mailing list