Next: Fluid/dynamic bindings, Previous: Various utilities, Up: System features
There are some basic filename manipulation facilities exported by the
filenames
structure.1
*Scheme-file-type*
is a symbol denoting the file extension that Scheme48 assumes for Scheme source files; any other extension, for instance in the filename list of a structure definition, must be written explicitly.*Load-file-type*
is a symbol denoting the preferable file extension to load files from. (*Load-file-type*
was used mostly in bootstrapping Scheme48 from Pseudoscheme or T long ago and is no longer very useful.)
File-name-directory
returns the directory component of the filename denoted by the string filename, including a trailing separator (on Unix,/
).File-name-nondirectory
returns everything but the directory component of the filename denoted by the string filename, including the extension.(file-name-directory "/usr/local/lib/scheme48/scheme48.image") => "/usr/local/lib/scheme48/" (file-name-nondirectory "/usr/local/lib/scheme48/scheme48.image") => "scheme48.image" (file-name-directory "scheme48.image") => "" (file-name-nondirectory "scheme48.image") => "scheme48.image"
Namelists are platform-independent means by which to name files. They are represented as readable S-expressions of any of the following forms:
(
directory basename [
type])
((
directory ...)
basename [
type])
Each atomic component — that is, the basename, the type/extension,
and each individual directory component — may be either a string or
a symbol. Symbols are converted to the canonical case of the host
operating system by namestring
(on Unix, lowercase); the case of
string components is not touched.
Converts namelist to a string in the format required by the host operating system.2 If namelist did not have a directory component, directory, a string in the underlying operating system's format for directory prefixes, is added to the resulting namestring; and, if namelist did not have a type/extension, default-type, which may be a string or a symbol and which should not already contain the host operating system's delimiter (usually a dot), is appended to the resulting namestring.
Directory or default-type may be
#f
, in which case they are not prefixed or appended to the resulting filename.(namestring 'foo #f #f) => "foo" (namestring 'foo "bar" 'baz) => "bar/foo.baz" (namestring '(rts defenum) "scheme" 'scm) => "scheme/rts/defenum.scm" (namestring '((foo bar) baz quux) "zot" #f) => "zot/foo/bar/baz.quux" (namestring "zot/foo/bar/baz.quux" #f "mumble") => "zot/foo/bar/baz.quux.mumble"
Scheme48 keeps a registry of filename translations, translations from filename prefixes to the real prefixes. This allows abstraction of actual directory prefixes without necessitating running Scheme code to construct directory pathnames (for example, in configuration files).
Adds a filename prefix translation, overwriting an existing one if one already existed.
Translates the first prefix of filename found in the registry of translations and returns the translated filename.
(set-translation! "s48" "/home/me/scheme/scheme48/scheme") (translate (namestring '(bcomp frame) "s48" 'scm)) => "/home/me/scheme/scheme48/scheme/bcomp/frame.scm" (translate (namestring "comp-packages" "s48" 'scm)) => "/home/me/scheme/scheme48/scheme/comp-packages.scm" (translate "s48/frobozz") => "/home/me/scheme/scheme48/scheme/frobozz" (set-translation! "scheme48" "s48") (translate (namestring '((scheme48 big) filename) #f 'scm)) => scheme48/big/filename.scm (translate (translate (namestring '((scheme48 big) filename) #f 'scm))) => "/home/me/scheme/scheme48/scheme/big/filename.scm"
One filename translation is built-in, mapping =scheme48/
to the
directory of system files in a Scheme48 installation, which on Unix is
typically a directory in /usr/local/lib
.
(translate "=scheme48/scheme48.image") => /usr/local/scheme48/scheme48.image
[1] The facilities Scheme48 provides are very rudimentary, and they are not intended to act as a coherent and comprehensive pathname or logical name facility such as that of Common Lisp. However, they served the basic needs of Scheme48's build process when they were originally created.
[2] However, the current standard distribution of Scheme48 is specific to Unix: the current code implements only Unix filename facilities.