Extended syntax for function arguments that allows for built-in guards, documentation, and macro-like keyword/optional arguments.
Macros like define accept an extended formals syntax. This syntax properly extends the normal syntax for a function's arguments used by defun, so you can still use a plain list of variable names if you like. But there are also some more interesting extensions.
Basic examples of some extended formals in a
(define split-up-string ((x stringp "The string to split") (separators (and (consp separators) (character-listp separators)) "Letters to split on -- <b>dropped from the result!</b>") &key (limit (or (not limit) (natp limit)) "Where to stop, @('nil') means @('(length x)')")) ...)
The general syntax for extended formals is:
Formals ::= (Formal* ; ordinary formals [&optional OptFormal*] ; optional positional formals [&key OptFormal*] ; optional keyword formals ) OptFormal ::= Formal ; optional formal w/NIL default | (Formal 'val) ; optional formal w/custom default Formal ::= (varname Item*) Item ::= xdoc ; documentation string | guard ; guard specifier | :key val ; other additional options
You can use
The default values for these parameters work just like in ordinary macros. The explicit quote serves to separate these from Items.
You can optionally describe your formals with some xdoc
documentation. This description will be embedded within some generated
As a convenient shorthand, the
For more complex guards, you can also write down arbitrary terms, e.g.,
above
&key (x 'atom) ;; x has no guard, default value 'atom vs. &key (x atom) ;; x has guard (atom x), default value nil vs. &key ((x atom) '3) ;; x has guard (atom x), default value 3
To make the formals syntax more flexible, other keyword/value options can be embedded within the formal.
The valid keywords and their interpretations can vary from macro to macro.
For instance, define doesn't accept any keyword/value options, but defaggregate fields have a
Some other features of extended formals are not evident in their syntax.
We generally expect macros that take extended formals to automatically
recognize ACL2::stobjs and insert appropriate
Future work (not yet implemented): certain guards like