Benjamin
Benjamin

Reputation: 85

Reading in a seqence from a text file in Common Lisp

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.

Upvotes: 2

Views: 399

Answers (1)

Vsevolod Dyomkin
Vsevolod Dyomkin

Reputation: 9451

(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)))))

Upvotes: 3

Related Questions