summaryrefslogtreecommitdiffstats
path: root/stdlib/getput.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-08-28 12:01:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-08-28 12:01:52 -0700
commit1a3fe1a084fd68ff4f10ef8cf031f347563b79ca (patch)
tree00f541955af1672e133064ef69abd976a15ec095 /stdlib/getput.tl
parenta2e0d566ef4d45d4915d43d035f6f21270d70178 (diff)
downloadtxr-1a3fe1a084fd68ff4f10ef8cf031f347563b79ca.tar.gz
txr-1a3fe1a084fd68ff4f10ef8cf031f347563b79ca.tar.bz2
txr-1a3fe1a084fd68ff4f10ef8cf031f347563b79ca.zip
New macro: close-lazy-streams.
* lib.c (lazy_stream_s): New symbol variable. (lazy_streams_binding): New static variable. (lazy_stream_register): New static function (lazy_stream_cons): If the stream is associated with a lazy cons, register it with lazy_stream_register. (obj_init): gc-protect lazy_streams_binding variable. Intern the sys:*lazy-streams* symbol. * lib.h (lazy_streams_s): Declared. * eval.c (eval_init): Register sys:*lazy-streams* special variable. * stdlib/getput.tl (close-lazy-streams): New macro. * autoload.c (getput_set_entries): Trigger autload on close-lazy-streams symbol. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'stdlib/getput.tl')
-rw-r--r--stdlib/getput.tl6
1 files changed, 6 insertions, 0 deletions
diff --git a/stdlib/getput.tl b/stdlib/getput.tl
index 0cf751a1..a1be729e 100644
--- a/stdlib/getput.tl
+++ b/stdlib/getput.tl
@@ -187,3 +187,9 @@
(defun command-put-jsons (cmd seq : flat-p mopt)
(with-stream (s (open-command cmd `w@mopt`))
(put-jsons seq s flat-p)))
+
+(defmacro close-lazy-streams (. body)
+ ^(let ((sys:*lazy-streams*))
+ (unwind-protect
+ (progn ,*body))
+ (mapdo (fun close-stream) sys:*lazy-streams*)))