defgeneric
(defgeneric name (param...) option...)
Defines a generic function and returns the name symbol. Methods are added with defmethod — specializers may appear on any required parameter, and a call runs the most specific matching method (parameters ranked leftmost-first); calling the generic with no matching method signals an error. A defgeneric is optional — the first defmethod implicitly creates the generic — but declares the lambda list every method must be congruent with (defmethod). A defgeneric that an existing method is not congruent with signals a program-error and leaves the generic as it was; evaluating a defgeneric again removes the methods its earlier (:method ...) clauses defined. On the compilation paths defgeneric is supported below the top level too -- in a let/let* body, whose bindings its (:method ...) clauses may close over, under a conditional, in a loop, in a function body -- and a second defgeneric of one name may not change the number of required parameters. The generic function is an ordinary function, so #'name and funcall work. name may also be a setf function name (setf reader) (see defmethod).
The lambda list may continue past the required parameters with &optional/&rest/&key (the dispatcher forwards the tail to the selected method), and inline (:method [qualifier] (param...) body...) clauses define methods in the defgeneric itself. (:documentation "...") is recorded and ignored, and so is (declare ...). (:argument-precedence-order param...) names the order the required parameters' specializers are compared in, most significant first, in place of leftmost-first: with (:argument-precedence-order y x), of two applicable methods the one with the more specific y specializer runs first. (:generic-function-class C) and (:method-class C) name the metaobject classes of the generic function and its methods (see add-method).
(:method-combination NAME [:most-specific-first | :most-specific-last]) selects one of the CLHS short-form combinations — progn, and, or, +, list, nconc, append, max, min. The effective method is then that operator applied to EVERY applicable method whose qualifier is the combination name, most specific first (:most-specific-last reverses the order); :around methods wrap the combined form as usual, while :before/:after are rejected, as CLHS requires. A primary method must carry the combination name as its qualifier: (defmethod encode-slots progn ((o point)) ...).
A combination define-method-combination defined is selected the same way, with its arguments, and standard names the default one. The remaining options are errors.
Calling a generic that has no applicable method signals an error (No applicable method: G on INTEGER), so it is shown here statically rather than as a runnable example:
(defgeneric g (x))
(g 1)