# HG changeset patch # User Steve Losh # Date 1487605236 0 # Node ID a0a09fcf271b62290ba5236a51df220c27972992 # Parent 9bcadce518537e39774c0eaf2f590c60ddf352ee Add read-all functions diff -r 9bcadce51853 -r a0a09fcf271b DOCUMENTATION.markdown --- a/DOCUMENTATION.markdown Fri Feb 17 13:11:46 2017 +0000 +++ b/DOCUMENTATION.markdown Mon Feb 20 15:40:36 2017 +0000 @@ -1008,6 +1008,22 @@ +## Package `LOSH.IO` + +Utilities for input/output/reading/etc. + +### `READ-ALL-FROM-FILE` (function) + + (READ-ALL-FROM-FILE PATH) + +Read all forms from the file at `path` and return them as a fresh list. + +### `READ-ALL-FROM-STRING` (function) + + (READ-ALL-FROM-STRING STRING) + +Read all forms from `string` and return them as a fresh list. + ## Package `LOSH.ITERATE` Custom `iterate` drivers and clauses. diff -r 9bcadce51853 -r a0a09fcf271b losh.lisp --- a/losh.lisp Fri Feb 17 13:11:46 2017 +0000 +++ b/losh.lisp Mon Feb 20 15:40:36 2017 +0000 @@ -2294,6 +2294,28 @@ (apply #'make-bset list)) +;;;; IO ----------------------------------------------------------------------- +(defun read-all-from-string (string) + "Read all forms from `string` and return them as a fresh list." + (iterate + (with done = (gensym)) + (with start = 0) + (for (values form pos) = (read-from-string string nil done + :start start)) + (while (not (eq form done))) + (collect form) + (setf start pos))) + +(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)))) + + ;;;; Gnuplot ------------------------------------------------------------------ (defun gnuplot-args% (&rest args) (mapcan (lambda (arg) (list "-e" arg)) diff -r 9bcadce51853 -r a0a09fcf271b make-docs.lisp --- a/make-docs.lisp Fri Feb 17 13:11:46 2017 +0000 +++ b/make-docs.lisp Mon Feb 20 15:40:36 2017 +0000 @@ -14,6 +14,7 @@ "LOSH.GNUPLOT" "LOSH.HASH-SETS" "LOSH.HASH-TABLES" + "LOSH.IO" "LOSH.ITERATE" "LOSH.LICENSING" "LOSH.MATH" diff -r 9bcadce51853 -r a0a09fcf271b package.lisp --- a/package.lisp Fri Feb 17 13:11:46 2017 +0000 +++ b/package.lisp Mon Feb 20 15:40:36 2017 +0000 @@ -141,6 +141,12 @@ :hash-table-contents :mutate-hash-values)) +(defpackage :losh.io + (:documentation "Utilities for input/output/reading/etc.") + (:export + :read-all-from-file + :read-all-from-string)) + (defpackage :losh.iterate (:use :iterate) ; need this for iterate's `for` symbol fuckery (:documentation "Custom `iterate` drivers and clauses.") @@ -285,6 +291,7 @@ :losh.gnuplot :losh.hash-sets :losh.hash-tables + :losh.io :losh.iterate :losh.licensing :losh.math