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

@ -1,9 +1,15 @@
(define-library (scheme file) (define-library (scheme file)
(export (export
call-with-input-file call-with-input-file
call-with-output-file call-with-output-file
with-input-from-file ;delete-file
with-output-from-file ;file-exists?
;open-binary-input-file
;open-binary-output-file
;open-input-file
;open-output-file
with-input-from-file
with-output-to-file
) )
(import (scheme base)) (import (scheme base))
(begin (begin
@ -11,6 +17,15 @@
(call-with-port (open-input-file string) proc)) (call-with-port (open-input-file string) proc))
(define (call-with-output-file string proc) (define (call-with-output-file string proc)
(call-with-port (open-output-file string) proc)) (call-with-port (open-output-file string) proc))
TODO: with-input-from-file (define (with-input-from-file string thunk) #f)
TODO: with-output-from-file (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) (import (scheme base)
(scheme file)) (scheme file)
(scheme write))
(with-output-to-file (with-output-to-file
"test.out" "test.out"