definitions
1.0.0General definitions reflection library.
Table of Contents
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.
Modifying Definitions
The library also includes an optional protocol for establishing, modifying, and removing definitions. To use this protocol, see the functions bind, (setf object), and unbind.
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 (1.4.8+)
- 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
No documentation provided. -
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 CONDITION BINDING-EXISTS
Error signalled when a new binding conflicts with an existing one. The condition contains the DESIGNATOR and TYPE that the conflicting binding was intended to be for. See TYPE See DESIGNATOR See BIND
-
EXTERNAL FUNCTION APROPOS-DEFINITIONS
- STRING
- &KEY
- TYPE
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
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 BIND
- DESIGNATOR
- TYPE
- OBJECT
Creates a new definition binding. Returns the canonical designator for the new binding. DESIGNATOR must be a designator to which a binding should be established. The designator may be normalised to some other, canonical designator. TYPE must be the name or an instance of a definition type for which a new binding should be established. If it is a name, it is automatically coerced to an instance of the definition type. Note that this parameter is purely for dispatch purposes. Modifying or inspecting the instance in any way leads to undefined behaviour. OBJECT must be some object in a predefined format that contains the definition information to which the new binding will point. What the structure of this object should be depends on the definition to bind. If a binding of the given type for the given designator already exists, or the new binding would conflict with another existing binding in some way, an error of type BINDING-EXISTS must be signalled. If the binding protocol is not implemented, an error of type NO-APPLICABLE-METHOD is signalled. If you add custom definition types, you are encouraged to add methods to this function that allow standardised addition of new definition bindings. Once a call to this function returns successfully, DEFINITION-P of the used designator and type must return T. See (SETF OBJECT) See UNBIND
-
EXTERNAL GENERIC-FUNCTION DEFINITION-P
- DESIGNATOR
- TYPE
- &KEY
- PACKAGE
Test whether a designator is designating a definition of the given type. You may pass T for the type to test whether the designator is designating any definition at all. This has the same semantics as calling FIND-DEFINITIONS with the designator, package, and type passed along, and checking that the returned list of definitions isn't empty. See FIND-DEFINITIONS
-
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 (SETF OBJECT)
- OBJECT
- DEFINITION
Updates an existing definition binding. Returns the passed OBJECT. OBJECT must be some object in a predefined format that contains the definition information to which the new binding will point. What the structure of this object should be depends on the definition to bind. If the updating protocol is not implemented, an error of type NO-APPLICABLE-METHOD is signalled. If you add custom definition types, you are encouraged to add methods to this function that allow standardised updating of definition bindings. See BIND See UNBIND
-
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 UNBIND
- DEFINITION
Removes the definition binding. If the given definition is already unbound, this function does nothing. If the unbinding protocol is not implemented for the given definition type, an error of type NO-APPLICABLE-METHOD is signalled. If you add custom definition types, you are encouraged to add methods to this function that allow standardised removal of definition bindings. Once a call to this function returns successfully, DEFINITION-P of the designator and type of the definition must return NIL. See (SETF OBJECT) See BIND
-
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 GENERIC-FUNCTION WHO-DEFINES
- OBJECT
Return all known definitions for a defined object. Returns a list of DEFINITIONs. This will attempt to do a reverse lookup of sorts. Given an object returned by OBJECT for a DEFINITION, this function should return said DEFINITION, and possibly others that bind the same object. This call can be costly as the default procedure relies on scanning through all known definitions to do the reverse lookup. See DEFINITION See OBJECT
-
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