Prev Up Next
All major Scheme dialects implement the R5RS
specification. By using only the features
documented in the R5RS, one can write Scheme code that
is portable across the dialects. However, the R5RS,
either for want of consensus or because of inevitable
system dependencies, remains silent on several matters
that non-trivial programming cannot ignore. The
various dialects have therefore had to solve these
matters in a non-standard and idiosyncratic manner.
This tutorial uses the MzScheme
dialect of Scheme, and thereby uses several
features that are nonstandard. The complete
list of the dialect-dependent features used
in this book is: the command-line (both for
opening a listener session and for shell scripts),
define-macro, delete-file, file-exists?,
file-or-directory-modify-seconds, fluid-let,
gensym, getenv, get-output-string,
load-relative, open-input-string,
open-output-string, read-line, reverse!,
system, when, and unless.
Some of these features (eg, file-exists?,
delete-file) are de facto standards and are present
in many Schemes. Some other features (eg, when,
unless) have more or less ``plug-in'' definitions
(given in this book) that can be loaded into any Scheme
dialect that doesn't have them primitively. The rest
require a dialect-specific definition
(eg, load-relative).
This chapter describes how to incorporate into your
Scheme dialect the nonstandard features used in this
book. For further detail about your Scheme
dialect, consult the documentation provided by its
implementor (sec U).
R.1 Invocation
To invoke the Guile
FSF listener, type guile. To invoke
SCM
Jaf, type scm.
To invoke STk Gal, type snow. This is the
``no window'' executable, which is enough for the purposes
of this book.
R.2 Init files
Many Scheme dialects load, if available, an
initialization file (or
init file), usually
supplied in the user's home directory. The init file
is a convenient location in which to place definitions
for nonstandard features. Eg, the nonstandard
procedure
file-or-directory-modify-seconds can be
added to the Guile dialect of Scheme by putting
the following code in Guile's init file, which
is ~/.guile:
(define file-or-directory-modify-seconds
(lambda (f)
(vector-ref (stat f) 9)))
The init files for SCM and STk are ~/ScmInit.scm
and ~/.stkrc respectively.
MzScheme also has an init file, viz, ~/.mzschemerc.
Note, however, that for the purposes of this text, you
don't need to insert code into ~/.mzschemerc,
since we don't use any nonstandard Scheme feature not
already defined in MzScheme.
R.3 Shell scripts
The initial line for a shell script written in Guile is:
":";exec guile -s $0 "$@"
In the script, the procedure-call (command-line) returns
the list of the script's name and arguments. To access
just the arguments, take the cdr of this list.
A shell script written in SCM starts out as:
":";exec scm -l $0 "$@"
In the script, the variable *argv* contains
the list of the Scheme executable name, the script's
name, the option -l, and the script's arguments.
To
access just the arguments, take the cdddr of this list.
STk shell scripts start out as:
":";exec snow -f $0 "$@"
In the script, the variable *argv* contains
the list of the script's arguments.
R.4 define-macro
The define-macro used in the text occurs in
the Scheme dialects Bigloo Ser, Gambit
Fee, Guile, MzScheme and Pocket Scheme
Goe. There are minor variations in
how macros are defined in the other Scheme dialects.
The rest of this section will point out how these
other dialects notate the following code fragment:
(define-macro MACRO-NAME
(lambda MACRO-ARGS
MACRO-BODY ...))
In MIT Scheme MIT, this is written as:
(syntax-table-define system-global-syntax-table 'MACRO-NAME
(macro MACRO-ARGS
MACRO-BODY ...))
In SCM and Kawa Bot:
(defmacro MACRO-NAME MACRO-ARGS
MACRO-BODY ...)
In STk:
(define-macro (MACRO-NAME . MACRO-ARGS)
MACRO-BODY ...)
R.5 load-relative
The procedure
load-relative may be defined for Guile as follows:
(define load-relative
(lambda (f)
(let* ((n (string-length f))
(full-pathname?
(and (> n 0)
(let ((c0 (string-ref f 0)))
(or (char=? c0 #\/)
(char=? c0 #\~))))))
(basic-load
(if full-pathname? f
(let ((clp (current-load-port)))
(if clp
(string-append (dirname (port-filename clp)) "/" f)
f)))))))
For SCM:
(define load-relative
(lambda (f)
(let* ((n (string-length f))
(full-pathname?
(and (> n 0)
(let ((c0 (string-ref f 0)))
(or (char=? c0 #\/)
(char=? c0 #\~))))))
(load (if (and *load-pathname* full-pathname?)
(in-vicinity (program-vicinity) f)
f)))))
For STk, the following definition for load-relative
works only if you discipline yourself to not use load:
(define *load-pathname* #f)
(define stk%load load)
(define load-relative
(lambda (f)
(fluid-let ((*load-pathname*
(if (not *load-pathname*) f
(let* ((n (string-length f))
(full-pathname?
(and (> n 0)
(let ((c0 (string-ref f 0)))
(or (char=? c0 #\/)
(char=? c0 #\~))))))
(if full-pathname? f
(string-append (dirname *load-pathname*)
"/" f))))))
(stk%load *load-pathname*))))
(define load
(lambda (f)
(error "Don't use load. Use load-relative instead.")))
Prev Up Next