The find-definitions-for-emacs function returns a list of definition specifiers (dspecs) associated with their source locations. The first item in a dspec denotes its type.
Swank clients like SLIME and MCLIDE can benefit from reliably determining the canonical type of a definition. However, the lisp implementations differ in the number of definition types and how they are named, and may also let users define custom definition types.
This ambiguity can be resolved by swank exposing information about the semantics of the implementation specific definition types and the relationship between them, such as:
(definterface definition-types () "Association list of definition type symbol, supertype(s), and optional attributes inherited by subtypes, where an attribute can be one of (:variable :class :method :function :macro) denoting the semantics of the definition type." '((variable nil :variable) (constant (variable)) (function nil :function) (macro (function) :macro) (generic (function)) (method nil :method) (class nil :class) (condition (class))))
Here is a Clozure specific implementation that adapts to new definition types:
(defimplementation definition-types () (loop with semantics = '((variable :variable)(class :class) (method :method)(function :function) (macro :macro)) for (type . def) in ccl::*definition-types* collect (list* type (loop for super in (class-direct-superclasses (class-of def)) for type = (car (rassoc (class-prototype super) ccl::*definition-types*)) when (and type (neq 't type)) collect type) (cdr (assoc type semantics))))
=>
((METHOD-COMBINATION-EVALUATOR NIL) (PPC-LAP NIL) (PPC32-VINSN NIL) (PACKAGE NIL) (CONSTANT (VARIABLE)) (VARIABLE NIL :VARIABLE) (METHOD-COMBINATION NIL) (DEFINITION-TYPE NIL) (STRUCTURE NIL) (CONDITION (CLASS)) (CLASS NIL :CLASS) (TYPE NIL) (STRUCTURE-ACCESSOR (FUNCTION)) (CALLBACK (FUNCTION)) (WRITER-METHOD (METHOD)) (READER-METHOD (METHOD)) (METHOD NIL :METHOD) (GENERIC-FUNCTION (FUNCTION)) (SETF-EXPANDER (MACRO)) (SYMBOL-MACRO (MACRO)) (COMPILER-MACRO (MACRO)) (MACRO (FUNCTION) :MACRO) (FUNCTION NIL :FUNCTION) (T NIL))
Here is a sample implementation for SBCL:
(defimplementation definition-types () (loop with semantics = '((defvar :variable)(defclass :class) (defmethod :method) (defun :function)(defmacro :macro)) with super = '((defconstant defvar)(define-condition defclass) (defgeneric defun) (define-compiler-macro defmacro)(defmacro defun)) for type in (cdr *definition-types*) by #'cddr collect (list* type (cdr (assoc type super)) (cdr (assoc type semantics))))
=>
((DEFVAR NIL :VARIABLE) (DEFCONSTANT (DEFVAR)) (DEFTYPE NIL) (DEFINE-SYMBOL-MACRO NIL) (DEFMACRO (DEFUN) :MACRO) (DEFINE-COMPILER-MACRO (DEFMACRO)) (DEFUN NIL :FUNCTION) (DEFGENERIC (DEFUN)) (DEFMETHOD NIL :METHOD) (DEFINE-SETF-EXPANDER NIL) (DEFSTRUCT NIL) (DEFINE-CONDITION (DEFCLASS)) (DEFCLASS NIL :CLASS) (DEFINE-METHOD-COMBINATION NIL) (DEFPACKAGE NIL) (:DEFTRANSFORM NIL) (:DEFOPTIMIZER NIL) (:DEFINE-VOP NIL) (:DEFINE-SOURCE-TRANSFORM NIL))
Here is a sample implementation for LispWorks:
(defimplementation definition-types () (loop with semantics = '((defvar :variable)(defclass :class) (method :method) (defun :function)(defmacro :macro)) with super = '((defconstant defvar) (define-condition defclass) (defgeneric defun) (compiler-macro defmacro) (defmacro defun)) for type in dspec:*dspec-classes* collect (list* type (cdr (assoc type super)) (cdr (assoc type semantics)))))
=>
((CAPI:DEFINE-INTERFACE NIL) (CAPI:DEFINE-LAYOUT NIL) (CAPI-INTERNALS:DEFINE-ELEMENT NIL) (CAPI-INTERNALS:DEFINE-AUTO-MENU NIL) (CAPI:DEFINE-MENU NIL) (EDITOR:DEFINE-TOP-LEVEL-FORM-PARSER NIL) (EDITOR:DEFCOMMAND NIL) (DEFSYSTEM NIL) (EXTERNAL-FORMAT::EF-FUNCTION NIL) (EXTERNAL-FORMAT:DEFINE-EXTERNAL-FORMAT-SYNONYM NIL) (EXTERNAL-FORMAT:DEFINE-EXTERNAL-FORMAT NIL) (FLI:DEFINE-FOREIGN-CALLABLE NIL) (FLI:DEFINE-FOREIGN-VARIABLE NIL) (FLI:DEFINE-FOREIGN-FUNCTION NIL) (FLI:DEFINE-FOREIGN-TYPE NIL) (FLI::FOREIGN-SYMBOL NIL) (FLI::DEFRAW-IMMEDIATE-FOREIGN-TYPE NIL) (SCM:DEFINE-PATCH-SEQUENCE NIL) (COMPILER::ADVICE-DEFINITION NIL) (COMPILER::ADVISED-FUNCTION-NAME NIL) (SYSTEM:DEFASM NIL) (METHOD-COMBINATION NIL) (METHOD NIL :METHOD) (DEFGENERIC (DEFUN)) (DEFINE-CONDITION (DEFCLASS)) (DEFCLASS NIL :CLASS) (DEFRESOURCE NIL) (PACKAGE NIL) (DEFSETF NIL) (STRUCTURE NIL) (STRUCTURE-CLASS NIL) (TYPE:TYPE-PREDICATE NIL) (DEFTYPE NIL) (TYPE NIL) (COMPILER-MACRO (DEFMACRO)) (DEFMACRO (DEFUN) :MACRO) (DEFUN NIL :FUNCTION) (FUNCTION NIL) (DEFINE-SYMBOL-MACRO NIL) (DEFCONSTANT (DEFVAR)) (DEFVAR NIL :VARIABLE) (VARIABLE NIL) (DSPEC:DEFINE-FORM-PARSER NIL) (DSPEC:DEFINE-DSPEC-ALIAS NIL) (DSPEC:DEFINE-DSPEC-CLASS NIL))
-- Terje Norderhaug terje@in-progress.com