如何以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)。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...