gpt4 book ai didi

口齿不清解码?

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:10 24 4
gpt4 key购买 nike

如何在 lisp 中解码二进制流我使用 with-open -file 并将参数作为元素类型'(无符号字节 8)传递,但作为数字而不是字符串返回请帮我解决这个问题

最佳答案

;;; Flexi-Streams "bivalent streams" solve the binary vs. character stream problem.
;;; You'll want to install QuickLisp and understand the REPL * and ** variables:

(require 'flexi-streams) ;; or (ql:quickload 'flexi-streams)

(with-open-file (out "foo.text" :direction :output)
(write-line "Foo" out)) ; "Foo"

(with-open-file (in "foo.text")
(read-line in)) ; "Foo", NIL

(with-open-file (in "foo.text" :element-type '(unsigned-byte 8))
(read-line in)) ;; read-line wrong stream type error

(with-open-file (in "foo.text" :element-type '(unsigned-byte 8))
(let ((s (make-array 3)))
(read-sequence s in) s)) ; #(70 111 111)

(map 'list #'code-char *) ; (#\F #\o #\o)

(map 'string #'code-char **) ; "Foo"

(with-open-file (raw "foo.text" :element-type 'flexi-streams:octet)
(with-open-stream (in (flexi-streams:make-flexi-stream raw))
(read-line in))) ; "Foo", NIL

;; Thanks to Edi Weitz for providing this essential tool.

关于口齿不清解码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4211710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com