# HG changeset patch # User Steve Losh # Date 1550979001 18000 # Node ID 1028d690ab05c1d1cbf103a3035d03c9a3af43c5 # Parent 957d61081ff7b27823790ef79a9d517fb2135d6b Add read-all diff -r 957d61081ff7 -r 1028d690ab05 package.lisp --- a/package.lisp Sat Feb 02 14:29:29 2019 -0500 +++ b/package.lisp Sat Feb 23 22:30:01 2019 -0500 @@ -82,6 +82,7 @@ (:use :cl :iterate :losh.quickutils) (:documentation "Utilities for input/output/reading/etc.") (:export + :read-all :read-all-from-file :read-all-from-string)) diff -r 957d61081ff7 -r 1028d690ab05 src/io.lisp --- a/src/io.lisp Sat Feb 02 14:29:29 2019 -0500 +++ b/src/io.lisp Sat Feb 23 22:30:01 2019 -0500 @@ -1,5 +1,11 @@ (in-package :losh.io) +(defun read-all (stream) + "Read all forms from `stream` and return them as a fresh list." + (iterate + (for v :in-stream stream) + (collect v))) + (defun read-all-from-string (string) "Read all forms from `string` and return them as a fresh list." (iterate @@ -14,10 +20,4 @@ (defun read-all-from-file (path) "Read all forms from the file at `path` and return them as a fresh list." (with-open-file (file path :direction :input) - (iterate - (with done = (gensym)) - (for form = (read file nil done)) - (while (not (eq form done))) - (collect form)))) - - + (read-all file)))