chickadee » feature-test » #+

#+read
#+FEATURE EXPR

Test FEATURE at read-time and, if present, expand to EXPR. FEATURE may be any feature expression permitted in a cond-expand, such as windows or (and windows macosx).

#+ can be used inside macros because it is expanded when the macro form is read, prior to macroexpansion. However, this requires a Chicken version >= 4.6.7, which will omit EXPR if the feature test is false. In earlier versions, the test expands to a (void) form, like the built-in #+. (void) forms are usually illegal inside macro bodies.

Here is an example that assumes Chicken is at least 4.6.7, which will omit EXPR on a false test:

(cond ((eq? x _af_inet) "internet address family")
      #+AF_UNIX
      ((eq? x _af_unix) "unix address family")
      (else "unknown address family")

If AF_UNIX is a registered feature at compile-time, it will be read as:

(cond ((eq? x _af_inet) "internet address family")
      ((eq? x _af_unix) "unix address family")
      (else "unknown address family")

If AF_UNIX is not a registered feature, it will be read as:

(cond ((eq? x _af_inet) "internet address family")
      (else "unknown address family")

However, if AF_UNIX is unregistered and you are using Chicken prior to 4.6.7, it will instead expand into the illegal:

(cond ((eq? x _af_inet) "internet address family")
      (##core#undefined)
      ((eq? x _af_unix) "unix address family")
      (else "unknown address family")

So be careful.