mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-12 15:37:35 +02:00
Defining with-in/output-from/to-file in terms of dynamic-wind.
This commit is contained in:
parent
8eb74156f9
commit
87970984c7
1 changed files with 16 additions and 16 deletions
|
@ -514,22 +514,6 @@
|
||||||
(close-output-port out)
|
(close-output-port out)
|
||||||
res))
|
res))
|
||||||
|
|
||||||
(define (with-input-from-file file thunk)
|
|
||||||
(let ((old-in (current-input-port))
|
|
||||||
(tmp-in (open-input-file file)))
|
|
||||||
(current-input-port tmp-in)
|
|
||||||
(let ((res (thunk)))
|
|
||||||
(current-input-port old-in)
|
|
||||||
res)))
|
|
||||||
|
|
||||||
(define (with-output-to-file file thunk)
|
|
||||||
(let ((old-out (current-output-port))
|
|
||||||
(tmp-out (open-output-file file)))
|
|
||||||
(current-output-port tmp-out)
|
|
||||||
(let ((res (thunk)))
|
|
||||||
(current-output-port old-out)
|
|
||||||
res)))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; values
|
;; values
|
||||||
|
|
||||||
|
@ -603,6 +587,22 @@
|
||||||
(let ((dk (%dk)))
|
(let ((dk (%dk)))
|
||||||
(%call/cc (lambda (k) (proc (lambda x (set-dk! dk) (k (%values x))))))))
|
(%call/cc (lambda (k) (proc (lambda x (set-dk! dk) (k (%values x))))))))
|
||||||
|
|
||||||
|
(define (with-input-from-file file thunk)
|
||||||
|
(let ((old-in (current-input-port))
|
||||||
|
(tmp-in (open-input-file file)))
|
||||||
|
(dynamic-wind
|
||||||
|
(lambda () (current-input-port tmp-in))
|
||||||
|
thunk
|
||||||
|
(lambda () (current-input-port old-in)))))
|
||||||
|
|
||||||
|
(define (with-output-to-file file thunk)
|
||||||
|
(let ((old-out (current-output-port))
|
||||||
|
(tmp-out (open-output-file file)))
|
||||||
|
(dynamic-wind
|
||||||
|
(lambda () (current-output-port tmp-out))
|
||||||
|
thunk
|
||||||
|
(lambda () (current-output-port old-out)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; syntax-rules
|
;; syntax-rules
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue