2.3 Parameterized types

The define-foreign-type and define-foreign-converter macros allow the definition of parameterized types. For example, assume you want to create a foreign type that matches the Lisp type unsigned-byte when supplied with an argument of one of 8, 16, or 32. The following code achieves this:

(fli:define-foreign-type unsigned-byte (&optional (bitsize '*))
  (case bitsize
    (8 '(:unsigned :byte))
    (16 '(:unsigned :short))
    (32 '(:unsigned :int))
    (otherwise (error "Illegal foreign type (~s ~s)"
                'unsigned-byte bitsize))))

This defines the new foreign type unsigned-byte that can be used anywhere within the FLI as one of

Specifying anything else returns an error.

LispWorks Foreign Language Interface User Guide and Reference Manual - 14 Mar 2008