Node:SRFI-0, Next:, Previous:About SRFI Usage, Up:SRFI Support

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-clause>+)
    | (cond-expand <cond-expand-clause>* (else <command-or-definition>))
  --> (<feature-requirement> <command-or-definition>*)
  --> <feature-identifier>
    | (and <feature-requirement>*)
    | (or <feature-requirement>*)
    | (not <feature-requirement>)
  --> <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 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:

    (use-modules (srfi srfi-8)))
  ;; 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))