From: Chris Hanson Date: Mon, 4 Jun 2001 17:38:50 +0000 (+0000) Subject: Implement WITH-OPEN-RESOURCE. X-Git-Tag: 20090517-FFI~2730 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=306d4287a25f6a33e592a8c90bd9f37c48fca296;p=mit-scheme.git Implement WITH-OPEN-RESOURCE. --- diff --git a/v7/src/imail/imail-core.scm b/v7/src/imail/imail-core.scm index 03d9d6b02..b8b80b457 100644 --- a/v7/src/imail/imail-core.scm +++ b/v7/src/imail/imail-core.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imail-core.scm,v 1.142 2001/06/03 01:42:28 cph Exp $ +;;; $Id: imail-core.scm,v 1.143 2001/06/04 17:38:50 cph Exp $ ;;; ;;; Copyright (c) 1999-2001 Massachusetts Institute of Technology ;;; @@ -470,6 +470,19 @@ (define-generic %open-resource (url)) +(define (with-open-resource url procedure) + (let ((resource #f)) + (dynamic-wind (lambda () + (set! resource (open-resource url)) + unspecific) + (lambda () (procedure resource)) + (lambda () + (let ((r resource)) + (if r + (begin + (set! resource #f) + (close-resource r #f)))))))) + ;; ------------------------------------------------------------------- ;; Close RESOURCE, freeing up connections, memory, etc. Subsequent ;; use of the resource must work, but may incur a significant time or