Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table
This commit is contained in:
1 parent
77843402fa
commit
4675bd1106
76 files changed
+2505
-14
No files matched your search
@@ -0,0 +1,30 @@
|
||||
;;; FILES 2: READING LINES (solution)
|
||||
|
||||
(defparameter *poem-file* "lisplings-poem.txt")
|
||||
|
||||
(defun save-poem ()
|
||||
(with-open-file (out *poem-file* :direction :output :if-exists :supersede)
|
||||
(format out "(lisp is life)~%")
|
||||
(format out "lambda forever~%")
|
||||
(format out "close the parens~%"))
|
||||
t)
|
||||
|
||||
(defun poem-lines ()
|
||||
(with-open-file (in *poem-file*)
|
||||
(poem-rest in)))
|
||||
|
||||
(defun poem-rest (in)
|
||||
(let ((line (read-line in nil nil)))
|
||||
(if line
|
||||
(cons line (poem-rest in))
|
||||
nil)))
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||
;;; them unchanged.
|
||||
;;; ------------------------------------------------------------------
|
||||
|
||||
(check (save-poem))
|
||||
(check-equal '("(lisp is life)" "lambda forever" "close the parens")
|
||||
(poem-lines))
|
||||
(check-equal 3 (length (poem-lines)))
|
||||
Reference in new issue
Block a user