temp.rkt
#lang racket/base

(require racket/file)

(require racket/contract)

(define temporary-directory (make-parameter "/tmp"))

(define (with-file next)
   (let ((name #f))
     (dynamic-wind
      (λ () (set! name (make-temporary-file "mztmp~a" #f (temporary-directory))))
      (λ () (next name))
      (λ () (when (and name (file-exists? name)) (delete-file name))))))

(provide/contract
  (with-file (-> (-> path? any) any))
  (rename temporary-directory directory parameter?))