バイナリ標準出力

common lispでは、標準出力にバイナリデータを出力する方法が定義されていない(多分)。

unix系(?)のOSの場合は、以下のように/dev/stdoutをopenすればバイナリデータを標準出力に出力できるようだ。

> (sb-ext:string-to-octets "標準出力")
--> #(230 168 153 230 186 150 229 135 186 229 138 155)

;; これはエラー
> (write-sequence #(230 168 153 230 186 150 229 135 186 229 138 155) *standard-output*)
--> Error: #<SB-SYS:FD-STREAM for "standard output" {A889A29}> is not a binary output stream.

;; こっちは大丈夫
> (with-open-file (out "/dev/stdout" :direction :output 
                                     :if-exists :overwrite 
                                     :element-type '(unsigned-byte 8))
    (write-sequence #(230 168 153 230 186 150 229 135 186 229 138 155) out))
"標準出力" ;※ 出力内容
--> #(230 168 153 230 186 150 229 135 186 229 138 155)

他にも、バイナリ標準入力には/dev/stdin、null入出力には/dev/nullが使える。
null出力の場合は、引数無しの(make-broadcast-stream)でも良いが、これは出力専用みたいなので、null入力を行いたい場合は、/dev/nullをopenする必要がある(これも多分)。