~ chicken-core (chicken-5) c88ea653a5e5350793c4c186f347eb9e304d08b0
commit c88ea653a5e5350793c4c186f347eb9e304d08b0
Author: Peter Bex <peter@more-magic.net>
AuthorDate: Wed Jun 22 20:49:54 2016 +0200
Commit: Peter Bex <peter@more-magic.net>
CommitDate: Wed Jun 22 20:49:54 2016 +0200
Add with-error-to-string and rename with-error-output-to-port to with-error-to-port
This improves compatibility with Bigloo, Stk, Gauche, SCM and Guile.
Signed-off-by: Evan Hanson <evhan@foldling.org>
diff --git a/NEWS b/NEWS
index 31b3270a..8436d1eb 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,9 @@
- `sleep` now suspends the current thread when threading is enabled,
otherwise it sleeps the process. The new `process-sleep` procedure
in unit posix can be used to sleep the process unconditionally.
+ - `with-error-output-to-port' from the ports module has been renamed
+ to the more common `with-error-to-port', and `with-error-to-string'
+ has been added for completeness (thanks to Michael Silver).
- Module system
- The compiler has been modularised, for improved namespacing. This
diff --git a/manual/Unit ports b/manual/Unit ports
index fa3c5e53..9e4d22e4 100644
--- a/manual/Unit ports
+++ b/manual/Unit ports
@@ -72,9 +72,9 @@ be a procedure of no arguments. {{FLUSH}} (if provided) is called
for flushing the output port.
-==== with-error-output-to-port
+==== with-error-to-port
-<procedure>(with-error-output-to-port PORT THUNK)</procedure>
+<procedure>(with-error-to-port PORT THUNK)</procedure>
Call procedure {{THUNK}} with the current error output-port
temporarily bound to {{PORT}}.
@@ -121,6 +121,14 @@ bound to an input-string-port with the contents of {{STRING}}.
Call procedure {{THUNK}} with the current output-port temporarily
bound to a string-output-port and return the accumulated output string.
+==== with-error-to-string
+
+<procedure>(with-error-to-string THUNK)</procedure>
+
+Call procedure {{THUNK}} with the current error output-port
+temporarily bound to a string-output-port and return the accumulated
+output string.
+
=== Port iterators
diff --git a/ports.scm b/ports.scm
index 7bb4479f..1744c356 100644
--- a/ports.scm
+++ b/ports.scm
@@ -47,11 +47,12 @@
port-fold
make-broadcast-port
make-concatenated-port
- with-error-output-to-port
+ with-error-to-port
with-input-from-port
with-input-from-string
with-output-to-port
- with-output-to-string)
+ with-output-to-string
+ with-error-to-string)
(import scheme chicken)
(import chicken.io)
@@ -183,17 +184,17 @@
(define (with-input-from-port port thunk)
(##sys#check-input-port port #t 'with-input-from-port)
- (fluid-let ([##sys#standard-input port])
+ (fluid-let ((##sys#standard-input port))
(thunk) ) )
(define (with-output-to-port port thunk)
(##sys#check-output-port port #t 'with-output-to-port)
- (fluid-let ([##sys#standard-output port])
+ (fluid-let ((##sys#standard-output port))
(thunk) ) )
-(define (with-error-output-to-port port thunk)
- (##sys#check-output-port port #t 'with-error-output-to-port)
- (fluid-let ([##sys#standard-error port])
+(define (with-error-to-port port thunk)
+ (##sys#check-output-port port #t 'with-error-to-port)
+ (fluid-let ((##sys#standard-error port))
(thunk) ) )
;;; Extended string-port operations:
@@ -216,10 +217,15 @@
(define with-output-to-string
(lambda (thunk)
- (fluid-let ([##sys#standard-output (open-output-string)])
+ (fluid-let ((##sys#standard-output (open-output-string)))
(thunk)
(get-output-string ##sys#standard-output) ) ) )
+(define with-error-to-string
+ (lambda (thunk)
+ (fluid-let ((##sys#standard-error (open-output-string)))
+ (thunk)
+ (get-output-string ##sys#standard-error) ) ) )
;;; Custom ports:
;
diff --git a/types.db b/types.db
index 1215d0dc..d2b2b0ba 100644
--- a/types.db
+++ b/types.db
@@ -1847,11 +1847,12 @@
(chicken.ports#port-fold (#(procedure #:enforce) chicken.ports#port-fold ((procedure (* *) *) * (procedure () *)) *))
(chicken.ports#make-broadcast-port (#(procedure #:clean #:enforce) chicken.ports#make-broadcast-port (#!rest output-port) output-port))
(chicken.ports#make-concatenated-port (#(procedure #:clean #:enforce) chicken.ports#make-concatenated-port (port #!rest input-port) input-port))
-(chicken.ports#with-error-output-to-port (#(procedure #:enforce) chicken.ports#with-error-output-to-port (output-port (procedure () . *)) . *))
+(chicken.ports#with-error-to-port (#(procedure #:enforce) chicken.ports#with-error-to-port (output-port (procedure () . *)) . *))
(chicken.ports#with-input-from-port (#(procedure #:enforce) chicken.ports#with-input-from-port (input-port (procedure () . *)) . *))
(chicken.ports#with-input-from-string (#(procedure #:enforce) chicken.ports#with-input-from-string (string (procedure () . *)) . *))
(chicken.ports#with-output-to-port (#(procedure #:enforce) chicken.ports#with-output-to-port (output-port (procedure () . *)) . *))
-(chicken.ports#with-output-to-string (#(procedure #:enforce) chicken.ports#with-output-to-string ((procedure () . *)) . *))
+(chicken.ports#with-output-to-string (#(procedure #:enforce) chicken.ports#with-output-to-string ((procedure () . *)) string))
+(chicken.ports#with-error-to-string (#(procedure #:enforce) chicken.ports#with-error-to-string ((procedure () . *)) string))
;; errno
Trap