summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-12-19 19:32:28 -0800
committerKaz Kylheku <kaz@kylheku.com>2023-12-19 19:32:28 -0800
commitdaf60d254b0f47fcdd2dec4046a4e97476da9eee (patch)
treea7340760fa611c16ec048f4a35bbab0951c90845 /stdlib
parent5253d51f5139008cf86c24235e394b409fd82808 (diff)
downloadtxr-daf60d254b0f47fcdd2dec4046a4e97476da9eee.tar.gz
txr-daf60d254b0f47fcdd2dec4046a4e97476da9eee.tar.bz2
txr-daf60d254b0f47fcdd2dec4046a4e97476da9eee.zip
New functions: read-objects, file-get-objects, ...
* parser.c (read_objects_common): New static function, formed from read_objects_from-string. (read_objects_from_string): Now wrapper for read_objects_common. (read_objects): New function. * parser.h (read_objects): Declared. * eval.c (eval_init): Register read-objects intrinsic. * autoload.c (getput_set_entries): Add three new symbols: file-get-objects, file-put-objects and file-append-objects. * stdlib/getput.tl (put-objects): New system function. (file-get-objects, file-put-objects, file-append-objects): New functions. * txr.1: Documented. * tests/018/getput.tl: New file.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/getput.tl17
1 files changed, 17 insertions, 0 deletions
diff --git a/stdlib/getput.tl b/stdlib/getput.tl
index fd62f911..8bc30598 100644
--- a/stdlib/getput.tl
+++ b/stdlib/getput.tl
@@ -62,6 +62,11 @@
(put-jsonl obj s flat-p))
t)
+(defun put-objects (list : (s *stdout*))
+ (each ((obj list))
+ (prinl obj s)
+ t))
+
(defun file-get (name : mopt)
(with-stream (s (open-file name `r@mopt`))
(read s)))
@@ -74,6 +79,18 @@
(with-stream (s (open-file name `a@mopt`))
(prinl obj s)))
+(defun file-get-objects (name : mopt (err-stream :))
+ (with-stream (s (open-file name `r@mopt`))
+ (read-objects s err-stream)))
+
+(defun file-put-objects (name seq : mopt)
+ (with-stream (s (open-file name `w@mopt`))
+ (put-objects seq s)))
+
+(defun file-append-objects (name seq : mopt)
+ (with-stream (s (open-file name `a@mopt`))
+ (put-objects seq s)))
+
(defun file-get-string (name : mopt)
(with-stream (s (open-file name `r@mopt`))
(get-string s)))