Node:SRFI-0, Next:SRFI-1, Previous:About SRFI Usage, Up:SRFI Support
SRFI-0 defines a means for checking whether a Scheme implementation has
support for a specified feature. The syntactic form cond-expand
,
which implements this means, has the following syntax.
<cond-expand> --> (cond-expand <cond-expand-clause>+) | (cond-expand <cond-expand-clause>* (else <command-or-definition>)) <cond-expand-clause> --> (<feature-requirement> <command-or-definition>*) <feature-requirement> --> <feature-identifier> | (and <feature-requirement>*) | (or <feature-requirement>*) | (not <feature-requirement>) <feature-identifier> --> <a symbol which is the name or alias of a SRFI>
When evaluated, this form checks all clauses in order, until it finds one whose feature requirement is satisfied. Then the form expands into the commands or definitions in the clause. A requirement is tested as follows:
and
form, all requirements must be satisfied. If no
requirements are given, it is satisfied, too.
or
form, at least one of the requirements must be
satisfied. If no requirements are given, it is not satisfied.
not
form, the feature requirement must not be
satisfied.
else
and it is the last
clause, it is satisfied if no prior clause matched.
If no clause is satisfied, an error is signalled.
Since cond-expand
is needed to tell what a Scheme implementation
provides, it must be accessible without using any
implementation-dependent operations, such as use-modules
in
Guile. Thus, it is not necessary to use any module to get access to
this form.
Currently, the feature identifiers guile
, r5rs
and
srfi-0
are supported. The other SRFIs are not in that list by
default, because the SRFI modules must be explicitly used before their
exported bindings can be used.
So if a Scheme program wishes to use SRFI-8, it has two possibilities:
First, it can check whether the running Scheme implementation is Guile,
and if it is, it can use the appropriate module:
(cond-expand (guile (use-modules (srfi srfi-8))) (srfi-8 #t)) ;; otherwise fail.
The other possibility is to use the --use-srfi
command line
option when invoking Guile (see Invoking Guile). When you do that,
the specified SRFI support modules will be loaded and add their feature
identifier to the list of symbols checked by cond-expand
.
So, if you invoke Guile like this:
$ guile --use-srfi=8
the following snippet will expand to 'hooray
.
(cond-expand (srfi-8 'hooray))