Reading in a seqence from a text file in Common Lisp

冷暖自知 提交于 2019-12-11 02:46:51

问题


I want to read in a textfile and make it a sequence and pass it on. How do I do that?

This is what I have so far:

(with-open-file (stream "filename.txt")
  (format t "~a~%" (read-line stream)))

The text file is like this:

Hello this is a sentence.
Hello this is second sentence.

回答1:


(with-open-file (in "filename.txt")
  (with-output-to-string (out)
    (loop :for line := (read-line in nil) :while line :do
       (write-line line out)))))


来源:https://stackoverflow.com/questions/8015766/reading-in-a-seqence-from-a-text-file-in-common-lisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!