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 <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 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.