# HG changeset patch # User Steve Losh # Date 1719164091 14400 # Node ID 443af0e76dd6d667783c9f9069c3ef6d553f3f45 # Parent 322aefbbcb9f03b41ce4e4b446ef8256cace001c Add with-eof-handled diff -r 322aefbbcb9f -r 443af0e76dd6 losh.asd --- a/losh.asd Tue Feb 20 11:36:38 2024 -0500 +++ b/losh.asd Sun Jun 23 13:34:51 2024 -0400 @@ -39,6 +39,7 @@ (:file "lists" :depends-on ("base")) (:file "mutation" :depends-on ("base")) (:file "shell" :depends-on ("base")) + (:file "streams" :depends-on ("base")) ;; 1 --------------------------------------------------------- (:file "arrays" :depends-on ("chili-dogs")) diff -r 322aefbbcb9f -r 443af0e76dd6 make-docs.lisp --- a/make-docs.lisp Tue Feb 20 11:36:38 2024 -0500 +++ b/make-docs.lisp Sun Jun 23 13:34:51 2024 -0400 @@ -28,6 +28,7 @@ "LOSH.RING-BUFFERS" "LOSH.SEQUENCES" "LOSH.SHELL" + "LOSH.STREAMS" "LOSH.WEIGHTLISTS" )) diff -r 322aefbbcb9f -r 443af0e76dd6 src/math.lisp --- a/src/math.lisp Tue Feb 20 11:36:38 2024 -0500 +++ b/src/math.lisp Sun Jun 23 13:34:51 2024 -0400 @@ -140,4 +140,3 @@ (floor _ (expt base position)) (mod _ base))) - diff -r 322aefbbcb9f -r 443af0e76dd6 src/package.lisp --- a/src/package.lisp Tue Feb 20 11:36:38 2024 -0500 +++ b/src/package.lisp Sun Jun 23 13:34:51 2024 -0400 @@ -103,6 +103,12 @@ :do-hash-set)) +(defpackage :losh.streams + (:use :cl :iterate :losh.base) + (:documentation "Utilities related to strings, reading, and/or printing.") + (:export + :with-eof-handled)) + (defpackage :losh.io (:use :cl :iterate :losh.base) @@ -508,6 +514,7 @@ :losh.ring-buffers :losh.sequences :losh.shell + :losh.streams :losh.weightlists ) diff -r 322aefbbcb9f -r 443af0e76dd6 src/streams.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/streams.lisp Sun Jun 23 13:34:51 2024 -0400 @@ -0,0 +1,9 @@ +(in-package :losh.streams) + +(defmacro with-eof-handled ((stream eof-error-p eof-value) &body body) + (alexandria:once-only (stream eof-error-p eof-value) + `(if (null (peek-char nil ,stream nil)) + (if ,eof-error-p + (error 'end-of-file) + ,eof-value) + (progn ,@body))))