| From: William D Clinger <will_at_ccs.neu.edu>
| Date: Wed, 15 Nov 2006 12:56:32 -0500
|
| ---
| This message is a formal comment which was submitted to formal-comment_at_r6rs.org, following the requirements described at:
http://www.r6rs.org/process.html
| ---
| Submitter: William D Clinger
| Email address: will_at_ccs.neu.edu
| Issue type: Enhancement
| Priority: Minor
| Component: I/O
| Report version: 5.91
| Summary: Please give us file-exists? and delete-file.
|
| Full description of issue:
|
| Programs often need to determine whether a file exists,
| and programs also need to clean up after themselves by
| deleting files.
|
| The draft R6RS does not provide any way to delete a file.
|
| The draft R6RS provides facilities that may be adequate
| for determining whether a file exists: the program would
| establish an exception handler for &i/o-file-exists-not
| conditions, try to open the file for input, and conclude
| that the file exists if and only no exception is raised.
| That technique is inconvenient, might be inefficient, and
| might be viewed as misuse of the exception system, whose
| stated purpose is to deal with exceptional situations;
| when searching several paths for an optional input or
| configuration file, the existence of that file is more
| exceptional than its non-existence.
|
| Current practice:
|
| A grep of Larceny's code base found more than a hundred
| uses of file-exists?, and more than a hundred uses of
| delete-file. A comparable number of uses were found in
| Gambit's code base.
FILE-EXISTS? and DELETE-FILE are "Universal SLIB Procedures", present
for all implementations
(
http://swiss.csail.mit.edu/~jaffer/slib_2.html#SEC16):
-- Function: file-exists? filename
Returns `#t' if the specified file exists. Otherwise, returns
`#f'. If the underlying implementation does not support this
feature then `#f' is always returned.
-- Function: delete-file filename
Deletes the file specified by FILENAME. If FILENAME can not be
deleted, `#f' is returned. Otherwise, `#t' is returned.
FILE-EXISTS? is typically inquiring if the file can be opened for
reading. If files can be opened read/write from R6RS, then one might
want to inquire about accessing a file in other ways.
| Of ten implementations surveyed, nine (Bigloo, Chicken,
| Gambit, Kawa, Larceny, MIT Scheme, MzScheme, Petite Chez,
| and scm) supply file-exists? and delete-file as part of
| their default runtime. Only one (Scheme 48) does not.
slib/scheme48.init defines these two procedures. Trying to excerpt
from slib-3a4 for Scheme-48-1.3:
,config
,load =scheme48/misc/packages.scm
(define-structure slib-primitives
(export (s48-access-mode :syntax)
s48-accessible?
s48-system)
(open (modify posix-files
(prefix s48-)
(expose access-mode accessible?))
(modify c-system-function (rename (system s48-system)))))
,user
,open slib-primitives
(define system s48-system)
(define (file-exists? f)
(s48-accessible? f (s48-access-mode exists)))
(define (delete-file file-name)
(system (string-append "rm " file-name)))
| Related issues:
|
| Programs also need to determine whether a directory exists,
| and to iterate through the files that are contained within
| a directory. I do not know whether these features are as
| ready for standardization as file-exists? and delete-file.
Mapping over (a subset of) files in a directory is not too hard if
SYSTEM is available; SLIB has directory-for-each:
http://swiss.csail.mit.edu/~jaffer/slib_7.html#SEC258
Received on Fri Nov 17 2006 - 12:31:38 UTC