This is the code to implement the 'cat' command with lisp, as is explained in the book ANSI Common Lisp, page 122.
(defun pseudo-cat (file) (with-open-file (str file :direction :input) (do ((line (read-line str nil 'eof) (read-line str nil 'eof))) ((eql line 'eof)) (format t "~A~%" line))))
Why is the read-line function run twice? I tried to run it with only one read-line, but the Lisp couldn't finish the code.
The syntax of DO variables is: variable, initialization form, update form. In this case, the initialization form is the same as the update form. But there is no shorthand for that case in DO, so you have to write it out twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With