From 68fedae3ffa8b35bcbdc4a0f7c08e8544c827d56 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 23 Jun 2015 21:00:28 -0400 Subject: [PATCH] Initial version of with-output-to-file, still needs debugging --- scheme/file.sld | 25 ++++++++++++++++++++----- test2.scm | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scheme/file.sld b/scheme/file.sld index 328d2b3a..0a083341 100644 --- a/scheme/file.sld +++ b/scheme/file.sld @@ -1,9 +1,15 @@ (define-library (scheme file) (export - call-with-input-file + call-with-input-file call-with-output-file - with-input-from-file - with-output-from-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-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 ' (open-output-file string)))) + (dynamic-wind + (lambda () (current-output-port ' new)) + thunk + (lambda () + (close-port (current-output-port)) + (current-output-port ' old))))) )) diff --git a/test2.scm b/test2.scm index 25d29577..ba3e1c8f 100644 --- a/test2.scm +++ b/test2.scm @@ -1,5 +1,6 @@ (import (scheme base) - (scheme file)) + (scheme file) + (scheme write)) (with-output-to-file "test.out"