Newsgroups: comp.lang.lisp
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!stanford.edu!lucid.com!karoshi!pab
From: pab@lucid.com (Peter Benson)
Subject: Re: multiple use of with-open-file, or with-open-stream
In-Reply-To: vinson@linc.cis.upenn.edu's message of 24 Jun 91 14:16:42 GMT
Message-ID: <PAB.91Jun24111117@challenger.lucid.com>
Sender: usenet@lucid.com
Organization: Lucid, Inc., Boulder, Utah office
References: <45084@netnews.upenn.edu>
Date: 24 Jun 91 11:11:16

You should use this idiom:

(let ((abort t)
      (list-of-file-to-open (find-files-to-open))
      (list-of-streams-to-close ()))
  (unwind-protect
      (progn 
        (dolist (file list-of-files-to-open)
          (push (open-my-file file) list-of-streams-to-close))
        (do-stuff-with-streams list-of-streams-to-close)
        (setq abort nil))
    (dolist (stream list-of-streams-to-close)
      (close stream :abort abort))))

If you bomb out in the middle of do-stuff-with-streams then all the files
will be closed properly.

If you macroexpand with-open-file you will find that it uses the same idiom
only with one file and stream.
