如何将行读取为 SIMPLE-BASE-STRING?
How to read lines as 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.
便携,没有。实现可以自由 return 他们认为合理的任何类型的字符串。
我会使用一个简单的包装函数,并可能声明它内联:
(declaim (inline read-simple-line))
(defun read-simple-line (stream)
(some-> (read-line stream nil)
(coerce 'simple-base-string)))
(Some->
来自 arrows
)。
所以,下面的代码
(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.
便携,没有。实现可以自由 return 他们认为合理的任何类型的字符串。
我会使用一个简单的包装函数,并可能声明它内联:
(declaim (inline read-simple-line))
(defun read-simple-line (stream)
(some-> (read-line stream nil)
(coerce 'simple-base-string)))
(Some->
来自 arrows
)。