gpt4 book ai didi

scheme - 使用 Scheme 检测二进制文件中的 EOF

转载 作者:行者123 更新时间:2023-12-04 07:02:43 24 4
gpt4 key购买 nike

(define (read-all-input)
(local ((define line (bytes->list (read-bytes 4))))
(if (eof-object? line)
empty
(cons line (read-all-input)))))

(void (read-all-input))

上面的代码失败,因为 bytes->list 需要一个字节字符串类型的参数,但给出了 #

最佳答案

#lang scheme

(define (read-all-input)
(let ((b (read-bytes 4)))
(cond
((eof-object? b) empty)
(else (cons b (read-all-input)))
)))

(void (read-all-input))

此函数将字节读入字节列表。

关于scheme - 使用 Scheme 检测二进制文件中的 EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592166/

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