如何解决如何以SIMPLE-BASE-STRING读取行?
因此,以下代码
(defun read-8bit-lines (path)
(with-open-file (stream path :element-type 'base-char :external-format :ascii)
(loop
for line = (read-line stream nil)
while line
collect line)))
将文件读为SIMPLE-ARRAY-CHARACTER
类型的字符串列表。我想改用SIMPLE-BASE-STRING
。我可以使用coerce
:
(defun read-8bit-lines (path)
(with-open-file (stream path :element-type 'base-char :external-format :ascii)
(loop
for line = (read-line stream nil)
while line
collect (coerce line 'simple-base-string))))
是否有一种方法可以不诉诸coerce
?我正在运行sbcl 2.0.5。
解决方法
不,不。实现可以自由返回它们认为合理的任何字符串。
我将使用一个简单的包装器函数,也许可以内联声明它:
(declaim (inline read-simple-line))
(defun read-simple-line (stream)
(some-> (read-line stream nil)
(coerce 'simple-base-string)))
({Some->
来自arrows
)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。