Initial version of with-output-to-file, still needs debugging

This commit is contained in:
Justin Ethier 2015-06-23 21:00:28 -04:00
parent ff634d8e18
commit 68fedae3ff
2 changed files with 22 additions and 6 deletions

View file

@ -2,8 +2,14 @@
(export
call-with-input-file
call-with-output-file
;delete-file
;file-exists?
;open-binary-input-file
;open-binary-output-file
;open-input-file
;open-output-file
with-input-from-file
with-output-from-file
with-output-to-file
)
(import (scheme base))
(begin
@ -11,6 +17,15 @@
(call-with-port (open-input-file string) proc))
(define (call-with-output-file string proc)
(call-with-port (open-output-file string) proc))
TODO: with-input-from-file
TODO: with-output-from-file
(define (with-input-from-file string thunk) #f)
(define (with-output-to-file string thunk)
;; Have to do this the long way since parameterize is not available
(let ((old (current-output-port))
(new (current-output-port '<param-convert> (open-output-file string))))
(dynamic-wind
(lambda () (current-output-port '<param-set!> new))
thunk
(lambda ()
(close-port (current-output-port))
(current-output-port '<param-set!> old)))))
))

View file

@ -1,5 +1,6 @@
(import (scheme base)
(scheme file))
(scheme file)
(scheme write))
(with-output-to-file
"test.out"