443af0e76dd6 default tip

Add with-eof-handled
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 23 Jun 2024 13:34:51 -0400
parents 322aefbbcb9f
children (none)
branches/tags default tip
files losh.asd make-docs.lisp src/math.lisp src/package.lisp src/streams.lisp

Changes

--- 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"))
--- 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"
 
         ))
--- 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)))
 
-
--- 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
 
    )
--- /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))))