(guile.info.gz) SRFI-0
Info Catalog
(guile.info.gz) About SRFI Usage
(guile.info.gz) SRFI Support
(guile.info.gz) SRFI-1
39.2 SRFI-0 - cond-expand
=========================
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:
* If it is a symbol, it is satisfied if the feature identifier is
supported.
* If it is an `and' form, all requirements must be satisfied. If no
requirements are given, it is satisfied, too.
* If it is an `or' form, at least one of the requirements must be
satisfied. If no requirements are given, it is not satisfied.
* If it is a `not' form, the feature requirement must _not_ be
satisfied.
* If the feature requirement is the keyword `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', `srfi-0' and
`srfi-6' 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 ( 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))
Info Catalog
(guile.info.gz) About SRFI Usage
(guile.info.gz) SRFI Support
(guile.info.gz) SRFI-1
automatically generated byinfo2html