[plt-scheme] Re: How do I create & use a temp file, ensuring it gets deleted?

From: Eric Hanchrow (offby1 at blarg.net)
Date: Fri Jul 21 09:24:44 EDT 2006

>>>>> "Jens" == Jens Axel Søgaard <jensaxel at soegaard.net> writes:

    Jens> Herman has a with-temporary-file in his io package at
    Jens> PLaneT.

Aha!  I didn't think to check PLaneT.  Thanks.

 ;; with-temporary-file
 ;; creates a temporary file and automatically deletes it when finished
 (define-syntax with-temporary-file
   (syntax-rules ()
     [(_ file (args ...) e1 e2 ...)
      (let ([file (make-temporary-file args ...)])
        (dynamic-wind
         void
         (lambda () e1 e2 ...)
         (lambda ()
           (when (file-exists? file)
             (delete-file file)))))]))

Looks awfully familiar :-)

-- 
Imagine this movie with Barbara Stanwyck and Fred MacMurray
and it would work for you.  Better still, just rent "Double
Indemnity" and the hell with it.
        -- Roger Ebert, on "Derailed (2005)"



Posted on the users mailing list.