From f853beeffa9c9b2983883ca1bfe3267c43c8edb3 Mon Sep 17 00:00:00 2001 From: Earl Hyatt Date: Sat, 5 Oct 2024 21:11:59 -0400 Subject: [PATCH 3/5] Add generalized variables for streams that error when used. * stream.el (seq-elt, stream-first, stream-rest): Signal an error when trying to use this function as a place for 'setf'. --- stream.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stream.el b/stream.el index 04b2be5..794b309 100644 --- a/stream.el +++ b/stream.el @@ -290,6 +290,10 @@ (defun stream-first (stream) Return nil if STREAM is empty." (stream--first (stream--force stream))) +(defun \(setf\ stream-first\) (_store _stream) + "Signal an error when trying to use `setf' on the head of a stream." + (error "Streams are not mutable")) + (defun stream-rest (stream) "Return a stream of all but the first element of STREAM." (setq stream (stream--force stream)) @@ -297,6 +301,10 @@ (defun stream-rest (stream) (stream-empty) (stream--rest stream))) +(defun \(setf\ stream-rest\) (_store _stream) + "Signal an error when trying to use `setf' on the tail of a stream." + (error "Streams are not mutable")) + (defun stream-append (&rest streams) "Concatenate the STREAMS. Requesting elements from the resulting stream will request the @@ -337,6 +345,9 @@ (cl-defmethod seq-elt ((stream stream) n) (setq n (1- n))) (stream-first stream)) +(cl-defmethod (setf seq-elt) (_store (_sequence stream) _n) + (error "Streams are not mutable")) + (cl-defmethod seq-length ((stream stream)) "Return the length of STREAM. This function will eagerly consume the entire stream." -- 2.34.1