1028d690ab05
Add read-all
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Sat, 23 Feb 2019 22:30:01 -0500 |
parents | 957d61081ff7 |
children | e844dad54ef3 |
branches/tags | (none) |
files | package.lisp src/io.lisp |
Changes
--- 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))
--- 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)))