Movatterモバイル変換


[0]ホーム

URL:


[LISPWORKS][Common Lisp HyperSpec (TM)][Previous][Up][Next]


MacroDEFMETHOD

Syntax:

defmethodfunction-name {method-qualifier}*specialized-lambda-list [[declaration* |documentation]]form*

=>new-method

function-name::= {symbol |(setfsymbol)}

method-qualifier::=non-list

specialized-lambda-list::= ({var | (var parameter-specializer-name)}*                             [&optional {var | (var [initform [supplied-p-parameter] ])}*]                             [&rest var]                             [&key{var | ({var | (keywordvar)} [initform [supplied-p-parameter] ])}*                                 [&allow-other-keys] ]                             [&aux {var | (var [initform] )}*] ) parameter-specializer-name::=symbol | (eql eql-specializer-form)

Arguments and Values:

declaration---adeclareexpression; not evaluated.

documentation---astring; not evaluated.

var---avariablename.

eql-specializer-form---aform.

Form---aform.

Initform---aform.

Supplied-p-parameter---variable name.

new-method---the newmethodobject.

Description:

The macrodefmethod defines amethod on ageneric function.

If(fboundpfunction-name) isnil, ageneric function is created with default values for the argument precedence order (each argument is more specific than the arguments to its right in the argument list), for the generic function class (theclassstandard-generic-function), for the method class (theclassstandard-method), and for the method combination type (the standard method combination type). Thelambda list of thegeneric function is congruent with thelambda list of themethod being defined; if thedefmethod form mentions keyword arguments, thelambda list of thegeneric function will mention ..... key (but no keyword arguments). Iffunction-name names anordinary function, amacro, or aspecial operator, an error is signaled.

If ageneric function is currently named byfunction-name, thelambda list of themethod must be congruent with thelambda list of thegeneric function. If this condition does not hold, an error is signaled. For a definition of congruence in this context, seeSection 7.6.4 (Congruent Lambda-lists for all Methods of a Generic Function).

Eachmethod-qualifier argument is anobject that is used by method combination to identify the givenmethod. The method combination type might further restrict what a methodqualifier can be. The standard method combination type allows forunqualified methods andmethods whose solequalifier is one of the keywords:before,:after, or:around.

Thespecialized-lambda-list argument is like an ordinarylambda list except that thenames of required parameters can be replaced by specialized parameters. A specialized parameter is a list of the form(varparameter-specializer-name). Only required parameters can be specialized. Ifparameter-specializer-name is asymbol it names aclass; if it is alist, it is of the form(eqleql-specializer-form). The parameter specializer name(eqleql-specializer-form) indicates that the corresponding argument must beeql to theobject that is the value ofeql-specializer-form for themethod to be applicable. Theeql-specializer-form is evaluated at the time that the expansion of thedefmethod macro is evaluated. If noparameter specializer name is specified for a given required parameter, theparameter specializer defaults to theclasst. For further discussion, seeSection 7.6.2 (Introduction to Methods).

Theform arguments specify the method body. The body of themethod is enclosed in animplicit block. Iffunction-name is asymbol, this block bears the samename as thegeneric function. Iffunction-name is alist of the form(setfsymbol), thename of the block issymbol.

Theclass of themethodobject that is created is that given by the method class option of thegeneric function on which themethod is defined.

If thegeneric function already has amethod that agrees with themethod being defined onparameter specializers andqualifiers,defmethod replaces the existingmethod with the one now being defined. For a definition of agreement in this context. seeSection 7.6.3 (Agreement on Parameter Specializers and Qualifiers).

Theparameter specializers are derived from theparameter specializer names as described inSection 7.6.2 (Introduction to Methods).

The expansion of thedefmethod macro ``refers to'' each specialized parameter (see the description ofignore within the description ofdeclare). This includes parameters that have an explicitparameter specializer name oft. This means that a compiler warning does not occur if the body of themethod does not refer to a specialized parameter, while a warning might occur if the body of themethod does not refer to an unspecialized parameter. For this reason, a parameter that specializes ont is not quite synonymous with an unspecialized parameter in this context.

Declarations at the head of the method body that apply to the method'slambda variables are treated asbound declarations whosescope is the same as the correspondingbindings.

Declarations at the head of the method body that apply to the functional bindings ofcall-next-method ornext-method-p apply to references to those functions within the method bodyforms. Any outerbindings of thefunction namescall-next-method andnext-method-p, and declarations associated with suchbindings areshadowed[2] within the method bodyforms.

Thescope offree declarations at the head of the method body is the entire method body, which includes any implicit local function definitions but excludesinitialization forms for thelambda variables.

defmethod is not required to perform any compile-time side effects. In particular, themethods are not installed for invocation during compilation. Animplementation may choose to store information about thegeneric function for the purposes of compile-time error-checking (such as checking the number of arguments on calls, or noting that a definition for the function name has been seen).

Documentation is attached as adocumentation string to themethodobject.

Examples: None.

Affected By:

The definition of the referencedgeneric function.

Exceptional Situations:

Iffunction-name names anordinary function, amacro, or aspecial operator, an error oftypeerror is signaled.

If ageneric function is currently named byfunction-name, thelambda list of themethod must be congruent with thelambda list of thegeneric function, or an error oftypeerror is signaled.

See Also:

defgeneric,documentation,Section 7.6.2 (Introduction to Methods),Section 7.6.4 (Congruent Lambda-lists for all Methods of a Generic Function),Section 7.6.3 (Agreement on Parameter Specializers and Qualifiers),Section 3.4.11 (Syntactic Interaction of Documentation Strings and Declarations)

Notes: None.


The followingX3J13 cleanup issues,not part of the specification, apply to this section:


[Starting Points][Contents][Index][Symbols][Glossary][Issues]
Copyright 1996-2005, LispWorks Ltd. All rights reserved.


[8]ページ先頭

©2009-2025 Movatter.jp