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


1.2 Feature based conditional expansion

The following bindings are exported by the library (vicare language-extensions cond-expand).

Syntax: define-cond-expand ?cond-expand ?feature-func ...

Expand to the definition of a syntax like cond-expand supporting all the features of the cond-expand from SRFI-0 and in addition supporting the features specified by a set of functions. Features supported by Vicare

?cond-expand must be an identifier representing the name of the new syntax.

The optional ?feature-func arguments must be expressions which, evaluated only once at expand time, must return functions; each of such functions must accept as single argument an identifier representing a feature and must return as single argument: #t if the feature is supported, #f otherwise.

In the following example we define a cond-expand syntax just like the one exported by SRFI-0:

#!r6rs
(import (rnrs)
  (vicare language-extensions cond-expand))

(define-cond-expand cond-expand)

(cond-expand
  ((and srfi-0 srfi-1)  #t)
  (else                 #f))
→ #t

in the following example we define a cond-expand that additionally recognises the features write and display:

#!r6rs
(import (rnrs)
  (vicare language-extensions cond-expand))

(define-cond-expand cond-expand
  (lambda (id)
    (free-identifier=? id #'display))
  (lambda (id)
    (free-identifier=? id #'write)))

(cond-expand
  ((or display write)   #t)
  (else                 #f))
→ #t

The following bindings are exported by the library (vicare language-extensions cond-expand helpers).

Syntax: define-cond-expand-identifiers-helper ?who ?feature-clause ...

Expand to the definition of a function bound to ?who which can be used as feature function in uses of the macro define-cond-expand.

Each of the optional ?feature-clause must have the following format:

(?feature-id ?expr)

where ?feature-id must be the feature identifier and ?expr must be an expression. The generated function compares the given identifier with each of ?feature-id, using free-identifier=?:

In the following example we define a cond-expand that additionally recognises the features write and display:

#!r6rs
(import (rnrs)
  (vicare language-extensions cond-expand)
  (for (vicare language-extensions cond-expand)
       expand))

(define-cond-expand cond-expand
  (let ()
    (define-cond-expand-identifiers-helper help
      (display        #t)
      (write          #t))
    help))

(cond-expand
  ((or display write)   #t)
  (else                 #f))
→ #t

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