[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What I want in R^5RS




      Date: Mon, 2 Dec 91 11:17:12 PST
      From: kend@data.rain.com (Ken Dickey)

      (FILE-EXISTS? <filename-string>) -- returns #t or #f
      (DELETE-FILE <filename-string>) --> unspecified

I don't think this is a viable mechanism.  The problem with FILE-EXISTS? is
that between the time it is called and the file is opened (or deleted or
whatever), it might get deleted by some other process (process is meant
loosely here... it could be the user, an OS process or a task of a
multiprocessing version of Scheme).  This would defeat the purpose of
the FILE-EXISTS? procedure.

I think it would be best to have a mechanism to atomically "grab" a file
and perform some operation on it (opening, deleting, renaming, etc).  For
example:

  (let ((p (GRAB-FILE "foo"
             (lambda () (open-input-file "foo"))
             (lambda () (error "Sorry, foo is not there")))))
    (write (read p))
    (close-port p))

Thus, one could define:

  (define (FILE-EXISTS? <filename-string>)
    (GRAB-FILE <filename-string>
      (lambda () #t)
      (lambda () #f)))

I'm sure someone can suggest a better name for GRAB-FILE and perhaps a
cleaner interface.  Maybe GRAB-FILE can be integrated to OPEN-INPUT-FILE.
If the file is not there, OPEN-INPUT-FILE would returns #f.  The procedure
DELETE-FILE would instead be DELETE-PORT... (you would have to open the file
before deleting it).

Other suggestions to solve the atomicity problem?

Marc Feeley