definitions
1.0.0General definitions reflection library.
About Definitions
This system implements a general definitions introspection library. It gives you the ability to retrieve definitions or bindings associated with designators such as symbols, packages, and names in general. For instance, it allows you to retrieve all function, type, variable, method, etc. definitions of a symbol.
How To
In order to list all discoverable definitions in a package, all you need to do is call find-definitions
like so:
(find-definitions "CL")
Each definition
is associated with a designator
that names it. Most, but not all, definitions also allow you to retrieve the object
that they define. If the designator is translatable to a symbol, the definition will also give you access to the symbol
, name
, package
, and visibility
within the package. Beyond that, you can also retrieve the associated documentation
and, depending on implementation support, the source-location
of the definition.
Some subclasses of the general definition
, like callable
give you access to further information like the arguments
or the qualifiers
.
If you would like to fuzzily search for definitions, you can use the apropos-definitions
function. Do note that this will likely return very long lists of definitions for searches that aren't very long.
Extending Definitions
Often time libraries and systems will introduce their own bindings and definitions that extend the environment. For instance, you might have a special kind of function definition that lives in its own namespace, or a particular kind of named resource. In this case it can be worthwhile to extend Definitions so that it can discover and handle information related to those definitions as well.
Adding new definition types is a matter of subclassing definition
, using define-definition-resolver
to handle the definition discovery, and adding methods to the relevant generic functions to provide the needed information.
Typically your definition will be a global-definition
, and thus be tied to a simple designator like a symbol that will find the definition in a global namespace. The global-definition
provides default implementations for symbol
, name
, package
, and visibility
, removing much of the need for duplicating those methods.
(defclass page (global-definition) ())
(define-simple-type-map page my-package:page)
(define-simple-definition-resolver page my-package:find-page)
(define-simple-object-lookup page my-package:find-page)
(define-simple-documentation-lookup page my-package:page)
The above will define a new definition type, page
, and add the missing methods to it, provided that the documentation is already handled through cl:documentation
on the my-package:page
type, and that my-package:find-page
returns the page object associated with a name. From there on out, find-definitions
will pick up page
definitions as well.
Depending on how your implementation tracks source information, and how well it is supported by this library, source-information
might work automatically on new definition types once a suitable object
method is in place. However, in general, it is not guaranteed that source tracking will be provided, let alone for definitions that are not standard.
Currently Supported Implementations
Some parts of this library such as the discovery of certain definitions, retrieval of some object bindings, and the source location tracking are implementation-specific. As such, in order to be complete, implementation-specific parts need to be written. Currently the following implementations are fully supported. Note that even if your implementation is not listed here, this library may still be useful.
- SBCL
- CCL
- Clasp
System Information
Definition Index
-
DEFINITIONS
- ORG.SHIRAKUMO.DEFINITIONS
No documentation provided.-
EXTERNAL CLASS ALIEN-TYPE
Alien-type definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS CALLABLE
Superclass for all definitions that represent objects that may be called. See DEFINITION See ARGUMENTS
-
EXTERNAL CLASS CLASS
Class definition representation. Note that this does not include conditions, or structures. See GLOBAL-DEFINITION
-
EXTERNAL CLASS COMPILER-MACRO
Compiler-macro definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS CONDITION
Condition definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS CONSTANT
Constant definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS DECLARATION
Declaration definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS DEFINITION
Base class for all definitions. Any definition type MUST subclass this class. See DESIGNATOR See OBJECT See SYMBOL See NAME See PACKAGE See TYPE See VISIBILITY See DOCUMENTATION See SOURCE-LOCATION
-
EXTERNAL CLASS FUNCTION
Function definition representation. Note that this does not include macros, compiler-macros, setf- expanders, or methods. See GLOBAL-DEFINITION
-
EXTERNAL CLASS GENERIC-FUNCTION
Generic-function definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS GLOBAL-DEFINITION
Superclass for global definitions reachable by a simple designator. This class provides standard implementations for OBJECT, SYMBOL, NAME, PACKAGE, VISIBILITY, DOCUMENTATION, and SOURCE-LOCATION. This means that all that's necessary to reach compliance for a new subtype of GLOBAL-DEFINITION is the implementation of an appropriate TYPE method. However, specific implementations of the other functions, particularly OBJECT, and DOCUMENTATION are usually needed in order to make all the information available. See DEFINITION See DESIGNATOR
-
EXTERNAL CLASS IR1-CONVERT
IR1-Convert definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS MACRO
Macro definition representation. Note that this does not include compiler-macros, setf-expanders, or symbol-macros. See GLOBAL-DEFINITION
-
EXTERNAL CLASS METHOD
Method definition representation. Note that this is not discoverable portably. See QUALIFIERS See GLOBAL-DEFINITION
-
EXTERNAL CLASS METHOD-COMBINATION
Method-combination definition representation. Note that this is not discoverable portably. See GLOBAL-DEFINITION
-
EXTERNAL CLASS OPTIMIZER
Optimizer definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS PACKAGE
Package definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS SETF-EXPANDER
Setf-expander definition representation. Note that this is not discoverable portably. Note that this does not include functions with a (SETF ..) designator. See GLOBAL-DEFINITION
-
EXTERNAL CLASS SOURCE-TRANSFORM
Source-transform definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS SPECIAL-OPERATOR
No documentation provided. -
EXTERNAL CLASS SPECIAL-VARIABLE
Special variable definition representation. Note that this is not discoverable portably. See GLOBAL-DEFINITION
-
EXTERNAL CLASS STRUCTURE
Structure definition representation. Note that this may not include structures that are defined as :VECTOR types. See GLOBAL-DEFINITION
-
EXTERNAL CLASS SYMBOL-MACRO
Symbol-macro definition representation. Note that this is not discoverable portably. See GLOBAL-DEFINITION
-
EXTERNAL CLASS TRANSFORM
Transform definition representation. See GLOBAL-DEFINITION
-
EXTERNAL CLASS TYPE
Superclass that represents type definitions. See GLOBAL-DEFINITION
-
EXTERNAL CLASS TYPE-DEFINITION
Type definition representation. Note that this is not discoverable portably. Note that this is only for TYPEDEF-defined types. See GLOBAL-DEFINITION
-
EXTERNAL CLASS VARIABLE
Superclass that represents variable definitions. See GLOBAL-DEFINITION
-
EXTERNAL CLASS VOP
VOP definition representation. See GLOBAL-DEFINITION
-
EXTERNAL FUNCTION APROPOS-DEFINITIONS
- STRING
- &KEY
- (TYPE T)
Fuzzily search for definitions matching the given string. The search is fuzzy in the following way: If a symbol's name contains the search string regardless of case, then the symbol is considered to match, and all definitions designated by the symbol are included in the result. See FIND-DEFINITIONS
-
EXTERNAL FUNCTION DEFINITION-RESOLVER
- NAME
- &OPTIONAL
- (ERRORP T)
Accessor to the definition resolver of the given name. A definition resolver is a function that accepts two arguments, a designator and a package, and returns a list of DEFINITION instances that are named by this designator. See DEFINITION See REMOVE-DEFINITION-RESOLVER See DEFINE-DEFINITION-RESOLVER See DEFINE-SIMPLE-DEFINITION-RESOLVER
-
EXTERNAL FUNCTION (SETF DEFINITION-RESOLVER)
- FUNCTION
- NAME
No documentation provided. -
EXTERNAL FUNCTION REMOVE-DEFINITION-RESOLVER
- NAME
Removes the definition resolver of the given name. See DEFINITION-RESOLVER
-
EXTERNAL GENERIC-FUNCTION ARGUMENTS
- CALLABLE
Returns the lambda-list of the callable. The secondary value of this function is :UNKNOWN if no known method of retrieving the lambda-list is available. In that case, the primary value is always NIL. A call to this function for any subtype of CALLABLE must not error. See CALLABLE
-
EXTERNAL GENERIC-FUNCTION DESIGNATOR
- DEFINITION
Returns the designator that names this definition. Note that a single designator may name many definitions. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION DOCUMENTATION
- DEFINITION
Returns the documentation string associated with this definition. This may be NIL if no documentation is defined or known. The secondary value of this function is :UNKNOWN if no known method of retrieving the docstring is available. In that case, the primary value is always NIL. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION FIND-DEFINITIONS
- DESIGNATOR
- &KEY
- PACKAGE
- TYPE
Find applicable definitions for the given designator. Depending on the type of the designator, the following happens: PACKAGE --- FIND-DEFINITIONS is called for each symbol in the package, regardless of whether the symbol was inherited, or internal. STRING --- FIND-DEFINITIONS is called on the package returned by FIND-PACKAGE on the designator. If no package is found, an error is signalled. T --- All definitions found by the definition resolvers for the designator are returned as a single list. This function should not error except for the above mentioned case when a string is passed that does not name a package. The package argument designates the package that the global definitions should be relative to. This is mostly relevant for the visibility of the definition. The type argument allows you to constrain the search to definitions of the given type. See DEFINITION See APROPOS-DEFINITIONS See DEFINITION-RESOLVER
-
EXTERNAL GENERIC-FUNCTION NAME
- DEFINITION
Returns the name of this definition as a string. For certain definitions this may be the same as the DESIGNATOR, or merely a simple mapping of the designator to a string. This function may return NIL if it is not applicable to reduce the designator to a string name. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION OBJECT
- DEFINITION
Returns the object that this definition defines. The secondary value of this function is :UNKNOWN if no known method of retrieving the object is available. In that case, the primary value is always NIL. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION PACKAGE
- DEFINITION
Returns the package this definition is tied to. Typically this can be derived from the SYMBOL of the definition. This function is primarily provided for completeness and ease of use. This function may return NIL if it is not applicable for the definition to be tied to a particular package. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION QUALIFIERS
- METHOD
Returns the list of qualifiers used for the method. A call to this function for any subtype of METHOD must not error. See METHOD
-
EXTERNAL GENERIC-FUNCTION SOURCE-LOCATION
- DEFINITION
Returns the source location information of this definition. A successful return will have the form of a plist with the following keys and values: :FILE --- A pathname to the file in which the definition was made. This pathname may be logical. :FORM --- The number of the toplevel form in which this definition was made. This means that in order to read the definition, this number of calls+1 to READ must be made. This value may be NIL. :OFFSET --- The offset in characters at which this definition was made. If :FORM is given, this offset is within the form that is indicated by the :FORM value. Otherwise, this offset is in terms of FILE-POSITION from the beginning of the file. This may be NIL if no source location is available or known. The secondary value of this function is :UNKNOWN if no known method of retrieving the source location is available. In that case, the primary value is always NIL. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION SYMBOL
- DEFINITION
Returns the symbol naming this definition. This is different from the designator in the sense that the designator may be a compound expression that can be mapped to a single symbol. For instance, the (SETF FOO) designator would be reduced to the symbol FOO. This function may return NIL if it is not applicable to reduce the designator to a symbol. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION TYPE
- DEFINITION
Returns the type of the object the definition defines. For cases where the definition can be instantiated, this is equivalent to calling TYPE-OF on an instance of such a definition. This function may NOT return NIL, and must always return some symbol that can be used to identify the type of the definition. Note that this symbol is not necessarily unique to the type of the definition, meaning multiple definitions may share the same name. A call to this function for any subtype of DEFINITION must not error. See DEFINITION
-
EXTERNAL GENERIC-FUNCTION VISIBILITY
- DEFINITION
Returns the visibility of the definition from its package. Returns one of the symbol status designators: :INTERNAL :EXTERNAL :INHERITED NIL A call to this function for any subtype of DEFINITION must not error. See CL:FIND-SYMBOL See DEFINITION
-
EXTERNAL MACRO DEFINE-DEFINITION-RESOLVER
- NAME
- ARGS
- &BODY
- BODY
Define a new definition resolver. This is mostly provided as a shorthand. See DEFINITION-RESOLVER
-
EXTERNAL MACRO DEFINE-SIMPLE-DEFINITION-RESOLVER
- CLASS
- LOOKUP-FUNCTION
- &BODY
- BODY
A simpler form to define a definition resolver. This comes in two forms, short-form and long-form: SHORT-FORM In this form, only LOOKUP-FUNCTION is provided, and must be a symbol that names the test-function. LONG-FORM In this form, LOOKUP-FUNCTION is a lambda-list, and BODY is the forms that make up the test-function. If the test-function returns successfully and returns non-NIL, then the definition resolver returns a list with a single instance of the given CLASS, providing the designator as the initarg for :DESIGNATOR. The name of the definition resolver is set to CLASS. See DEFINE-DEFINITION-RESOLVER
-
EXTERNAL MACRO DEFINE-SIMPLE-DOCUMENTATION-LOOKUP
- CLASS
- DOCUMENTATION-TYPE
A simpler form to define the documentation lookup. This simply delegates the lookup to CL:DOCUMENTATION, using the provided arguments. If the DOCUMENTATION-TYPE is T, then CL:DOCUMENTATION is called with the OBJECT of the definition. Otherwise, CL:DOCUMENTATION is called with the DESIGNATOR of the definition and the provided DOCUMENTATION-TYPE. See DOCUMENTATION See CL:DOCUMENTATION See OBJECT See DESIGNATOR
-
EXTERNAL MACRO DEFINE-SIMPLE-OBJECT-LOOKUP
- CLASS
- LOOKUP-FUNCTION
- &BODY
- BODY
A simpler form to define the OBJECT method. This comes in two forms, short-form and long-form: SHORT-FORM In this form, only LOOKUP-FUNCTION is provided, and must be a symbol that names the lookup-function. LONG-FORM In this form, LOOKUP-FUNCTION is a lambda-list, and BODY is the forms that make up the lookup-function. The lookup-function must accept a single argument, the definition instance, and must either return the object that the definition defines, or two values: NIL and :UNKNOWN. See OBJECT
-
EXTERNAL MACRO DEFINE-SIMPLE-TYPE-MAP
- CLASS
- TYPE
A simpler form to define the type lookup. This simply defines a method on TYPE for the given class, returning the TYPE symbol. See TYPE