[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue: DEFINITION-FUNCTIONS



I promised I would submit a proposal for "named definitions" for making
documentation etc more extensible in Common Lisp.  I don't have a formal
proposal, but I've been sitting on this  very rough draft...  


- - - - 
A "definition type" a symbol, like one of the following
	function (including defun, defmacro, define-modify-macro...)
	setf  
	variable
	type


Definition types are used by several functions, including DOCUMENTATION.

A defining form, such as a form introduced with DEFUN, DEFSTRUCT, or
whatever, is said to give a given definition type to a specific name.
Frequently, a definition name is a symbol, but need not be.

(definition-type form)
     Given a form (such as DEFUN, DEFMACRO and the like) returns the
type of thing defined by it.
      (Can be either a form or else the symbol that introduces such a
form).
     DEFSTRUCT, DEFTYPE => TYPE
     DEFMACRO, DEFUN, DEFINE-MODIFY-MACRO, ... => FUNCTION
     DEFSETF => SETF
     DEFVAR, DEFPARAMETER, DEFCONST => VARIABLE

(definition-name form)
      Given a form (no symbol allowed), returns the name of the thing
defined. Often SECOND, but e.g.
     with DEFSTRUCT might do more processing.


(documentation name definition-type)
	As before, type can be any definition type.

(delete-definition name definition-type)
	delete all effects of name having a definition of type
	(delete-definition name 'function)  replaces (fmakunbound name)

	(delete-definition name 'variable)  replaces (makunbound name)

For adding more:

(def-definition-type type-name description &key undefiner)
	Define type-name as a new kind of definition type.
	Undefiner is a function which will remove a definition


(defdefiner definer-name type &key undefiner name-function)
	says that definer-name defines things of type.
	Undefiner says how to remove 'em
	name-function, defaults to second, says, given an expression
		which starts with definer-name, what the name of the thing is, e.g.,

	(defdefiner defun function :undefiner #'fmakunbound :name-function
#'second)

	(defdefiner defstruct type :undefiner #'si:remove-structure-definition
			:name-function #'(lambda (x) (if (consp (second x)) (car (second x))
(Second x)))))

	Note that when you undefine a name using delete-definition, *all* of
the known undefiners
	(both the general one supplied with def-define-type and the specific
one defined
	for each definer with defdefiner) are applied. The undefiner should not
error
	if there is no definition. 

	function is defined by (DEFINE-MODIFY-MACRO DEFMACRO DEFUN) 
	type is defined by  DEFTYPE DEFSTRUCT
	variable is defined by  DEFCONSTANT DEFPARAMETER DEFVAR
	setf is defined by DEFSETF and DEFINE-SETF-METHOD
	define-type is defined by DEF-DEFINE-TYPE


(ed name &optional type)  
	Optional type allows you to say which definition if there is more than
one.

- - - - - - - - - - -
The following make sense in some environments:


(has-definition-p name definition-type &key)
	True if name has some definition of given type 

(symbol-definition-types name)
	Return list of all types for which name has a definition

- - - - - - - - -

With the error proposal, DEFINE-PROCEED-FUNCTION would define function,
too.
With CLOS, DEFCLASS would define a class.

This is awkwardly said, so I may have to explain it better: definers are
for things that define the *whole thing*, for which other definitions
are mutually exclusive.  Thus, a defmethod doesn't define the generic
function, it only defines a piece of the generic function. So (defmethod
frob ((a widget) ...) ...) can't be a "definer" for the function frob. 

There is some design choice of whether it is a definer for the function
(:method frob widget) (since definition names need not be symbols) or
whether it is the definer for the method (frob widget).  I think this
need not be nailed down by the definition protocol.

I think this is separate from the "function spec" proposal because
"function specs" have to do with identifying pieces of executable code
which might have breakpoints, etc. assigned to them.