|
Teach Yourself Scheme in Fixnum Days
introduction to the programming language Scheme">
|
Dialect name | Command | Init file |
Bigloo | bigloo | ~/.bigloorc |
Chicken | csi | ~/.csirc |
Gambit | gsi | ~/gambc.scm |
Guile | guile | ~/.guile |
Kawa | kawa | ~/.kawarc.scm |
MIT Scheme (Unix) | scheme | ~/.scheme.init |
MIT Scheme (Win) | scheme | ~/scheme.ini |
MzScheme (Unix, Mac OS X) | mzscheme | ~/.mzschemerc |
MzScheme (Win, Mac OS Classic) | mzscheme | ~/mzschemerc.ss |
SCM | scm | ~/ScmInit.scm |
STk | snow | ~/.stkrc |
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.
define-macro
The define-macro
used in the text occurs in
the Scheme dialects Bigloo [29],
Chicken [31], Gambit
[6], Guile, MzScheme and Pocket Scheme
[15]. 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 [25] version 7.7.1 and later, this is written as:
(define-syntax MACRO-NAME (rsc-macro-transformer (let ((xfmr (lambda MACRO-ARGS MACRO-BODY ...))) (lambda (e r) (apply xfmr (cdr e))))))
In older versions of MIT Scheme:
(syntax-table-define system-global-syntax-table 'MACRO-NAME (macro MACRO-ARGS MACRO-BODY ...))
(defmacro MACRO-NAME MACRO-ARGS MACRO-BODY ...)
In STk [14]:
(define-macro (MACRO-NAME . MACRO-ARGS) MACRO-BODY ...)
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.")))
11 We will
use ~/filename
to denote the file called
filename
in the user's home directory.