From 5e714a3068a3cfe9acdc28aa6bfe0c79589edf4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 10 Apr 2023 22:44:16 +0200 Subject: Add ->port. --- module/hnh/util/io.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'module/hnh/util/io.scm') diff --git a/module/hnh/util/io.scm b/module/hnh/util/io.scm index d73a1de8..09900f8d 100644 --- a/module/hnh/util/io.scm +++ b/module/hnh/util/io.scm @@ -5,7 +5,8 @@ open-output-port read-lines with-atomic-output-to-file - call-with-tmpfile)) + call-with-tmpfile + ->port)) (define (open-input-port str) (if (string=? "-" str) @@ -72,3 +73,10 @@ (begin1 (proc port filename) (close-port port)))))) + +(define (->port port-or-string) + (cond ((port? port-or-string) port-or-string) + ((string? port-or-string) (open-input-string port-or-string)) + (else (scm-error 'misc-error "->port" + "Not a port or string" + (list port-or-string) #f)))) -- cgit v1.2.3