Example usage of DESCRIBE
The snippet can be accessed without any authentication.
Authored by
Michael Babich
This is an example of interactively using Common Lisp's describe
in the REPL.
*slime-repl sbcl* 3.55 KiB
ZR/UTIL> (describe 'define-function)
ZOMBIE-RAPTOR/UTIL/UTIL:DEFINE-FUNCTION
[symbol]
DEFINE-FUNCTION names a macro:
Lambda-list: (ZOMBIE-RAPTOR/UTIL/UTIL::NAME-AND-OPTIONS
ZOMBIE-RAPTOR/UTIL/UTIL::TYPED-LAMBDA-LIST &BODY
ZOMBIE-RAPTOR/UTIL/UTIL::BODY)
Documentation:
Define a function that is (potentially) 'statically typed' using type
declarations, which have implementation-specific behavior. The types,
which are not required, are provided in a similar way to defmethod: a
list of two items, where the first is the name and the second is the
type.
Keyword and optional arguments can also have a type. When they are
typed, a default value must be provided and the type comes after the
default value. That is, the sublist specifying the typed argument if
it is a keyword or optional is:
(binding &optional default type)
The provided default value for an optional or keyword argument can be
a value that is not of the required type. In that case, there will be
an error if the caller does not provide a value of the valid type. For
instance, NIL can be used as a default value even if it is not of the
type. This might be desirable if the caller is supposed to provide
their own value. Be careful if you do this because DECLARE is not
required to always error in such situations. This will only lead to
potentially problematic behavior in SBCL with (safety 0).
name-and-options is either a symbol, in which case it is the name, or
it is a list with the CAR being the name and the CDR being an options
plist. The options that can be provided are described below:
:inline tells the compiler that it may inline the function.
:optimize and :debug automatically generate reasonable optimization
declarations for the function if one or both are t.
The :default-type is the type that an argument is assumed to be if no
type is provided. If default-type is NIL then there is no checking for
arguments without a type provided. This is logically equivalent to
providing a default-type of T, but it is potentially more efficient to
use NIL here because then it does not check that the arguments are T.
If :check-type is T, then `check-type' is used instead of type
declarations. Always use `check-type' if you want to be able to fix
the type errors at run time. Never use `check-type' if the types are
only there for efficiency hints in implementations with type
declarations.
Conditionally use `check-type' if the optimal type checking on each
implementation is desired (e.g. check in CLISP and declare in SBCL)
even if that means that the type errors are not fixable at run time in
some implementations (e.g. SBCL with type declarations). This third
option will eventually be the default (i.e. the default value will be
different on different implementations), but currently the default is
type declarations everywhere.
If :return is non-NIL then that is the return type of the function. It
is either a single value or a syntactic (unquoted) list of values. An
ftype is only declared if check-type is NIL and a return type is
provided.
Example usage:
(define-function foo ((x single-float) (y double-float) &optional (z 42 fixnum))
(+ x y z))
(define-function (bar :inline t :return single-float) ((x integer) (y single-float))
(* x y))
Source file: /home/michael/git/zombie-raptor/util/util.lisp
; No value
ZR/UTIL>
Please register or sign in to comment