Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #37 from OlegTheCat/fix-dolines
Make dolines evaluate src only once
  • Loading branch information
vseloved committed Jul 26, 2018
2 parents 2674eed + 5115c1f commit cdeb1dd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/string.lisp
Expand Up @@ -96,14 +96,15 @@
(defmacro dolines ((line src &optional result) &body body)
"Iterate over each LINE in SRC (a stream or path to a file) as in DOLIST."
(let ((in (gensym)))
`(if (streamp ,src)
(loop :for ,line := (read-line ,src nil nil) :while ,line :do
(progn ,@body)
:finally (return ,result))
(with-open-file (,in ,src)
(loop :for ,line := (read-line ,in nil nil) :while ,line :do
(progn ,@body)
:finally (return ,result))))))
(once-only (src)
`(if (streamp ,src)
(loop :for ,line := (read-line ,src nil nil) :while ,line :do
(progn ,@body)
:finally (return ,result))
(with-open-file (,in ,src)
(loop :for ,line := (read-line ,in nil nil) :while ,line :do
(progn ,@body)
:finally (return ,result)))))))

(defmacro with-out-file ((var path) &body body)
`(with-open-file (,var ,path :direction :output
Expand Down

0 comments on commit cdeb1dd

Please sign in to comment.