<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>On Nov 10, 2016, at 4:00 AM, Zach Beane <<a href="mailto:xach@xach.com">xach@xach.com</a>> wrote:</div><div><div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>Is there an easy way to create a bivalent stream to output to a file?<br><br>If there isn't an easy way, what's the least worst way?<br><br>Thanks,<br>Zach<br></div></blockquote><br></div><div>Here's one way:</div><div><br></div><div><div><font class="Apple-style-span" face="Monaco">(defun enable-char-output (stream)</font></div><div><font class="Apple-style-span" face="Monaco"> "Call this to enable character output to a binary stream in CCL."</font></div><div><font class="Apple-style-span" face="Monaco"> (let ((ioblock (ccl::basic-stream-ioblock stream)))</font></div><div><font class="Apple-style-span" face="Monaco"> (setf (ccl::ioblock-write-char-function ioblock) 'ccl::%ioblock-write-u8-encoded-char</font></div><div><font class="Apple-style-span" face="Monaco"> (ccl::ioblock-write-simple-string-function ioblock) 'ccl::%ioblock-write-u8-encoded-simple-string)))</font></div><div><font class="Apple-style-span" face="Monaco"><br></font></div><div><font class="Apple-style-span" face="Monaco">(defun test-bivalent (&optional (path #P"ccl:bivalent.txt"))</font></div><div><font class="Apple-style-span" face="Monaco"> (with-open-file (stream path :direction :output :if-exists :supersede</font></div><div><font class="Apple-style-span" face="Monaco"> :sharing nil</font></div><div><font class="Apple-style-span" face="Monaco"> :element-type '(UNSIGNED-BYTE 8))</font></div><div><font class="Apple-style-span" face="Monaco"> ; make it possible for CCL to write characters to binary streams</font></div><div><font class="Apple-style-span" face="Monaco"> (enable-char-output stream)</font></div><div><font class="Apple-style-span" face="Monaco"> (write-sequence "STRING TEST" stream)</font></div><div><font class="Apple-style-span" face="Monaco"> (write-char #\x stream)</font></div><div><font class="Apple-style-span" face="Monaco"> (write-byte #x20 stream)</font></div><div><font class="Apple-style-span" face="Monaco"> (write-byte #x0D stream)</font></div><div><font class="Apple-style-span" face="Monaco"> (write-byte #x0A stream)))</font></div></div></div><div><font class="Apple-style-span" face="Monaco"><br></font></div></body></html>