Next: , Previous: , Up: posix   [Index]


4.3 Feature–based expansion

Syntax: cond-expand (?feature-requirement ?body0 ?body …) …

Process the given clauses in left–to–right order and expand to the sequence of ?body forms from the first clause for which the ?feature-requirement is satisfied.

This syntax supports all the features defined by cond-expand from SRFI-0 (see Features supported by Vicare), and in addition it supports a feature for each system function exported by (vicare posix); such features use the identifier exported by the library as feature requirement.

As example, let’s say we want to evaluate some code if truncate is supported, otherwise we do something else; we write the following:

(import (vicare)
  (prefix (vicare posix) px.))

(px.cond-expand
  (px.truncate
   (do-something))
  (else
   (do-something-else)))

and if we want to do it only on a GNU+Linux host:

(import (vicare)
  (prefix (vicare posix) px.))

(px.cond-expand
  ((or linux px.truncate)
   (do-something))
  (else
   (do-something-else)))