4.3 Defun preprocessor

The defun preprocessor allows for convenient definition of Lisp functions with optional and keyword arguments and the use of Lisp symbols in ECL’s own C source code. It generates the C code necessary to use optional function arguments and to access symbols in ECL’s builtin symbol table.

Usage:

        dpp [in-file [out-file]]

The file named in-file is preprocessed and the output will be written to the file whose name is out-file. If in-file is "-" program is read from standard input, while if out-file is "-" C-program is written to standard output.

The function definition:

@(defun name ({var}*
              [&optional {var | (var [initform [svar]])}*]
              [&rest var]
              [&key {var |
                     ({var | (keyword var)} [initform [svar]])}*
                    [&allow_other_keys]]
              [&aux {var | (var [initform])}*])

        C-declaration

@ {

        C-body

} @)

name is the name of the lisp function

&optional may be abbreviated as &o.
&rest may be abbreviated as &r.
&key may be abbreviated as &k.
&allow_other_keys may be abbreviated as &aok.
&aux may be abbreviated as &a.

Each variable becomes a C variable.

Each supplied-p parameter becomes a boolean C variable.

Initforms are C expressions. If an expression contains non-alphanumeric characters, it should be surrounded by backquotes (‘).

Function return:

        @(return {form}*);

Return function expands into a lexical block {}, so if it’s used inside if/else, then it should be enclosed, even if we use sole @(return);, because ";" will be treated as the next instruction.

Symbols:

@'name'

Expands into a C statement, whole value is the given symbol from symbols_list.h

@[name]

Expands into a C statement, whole value is a fixnum corresponding to the index in the builtin symbols table of the given symbol from symbols_list.h. Used for handling type errors.