In Common Lisp, you can read the following from the specification:
7.6.1 Introduction to Generic Functions
When a defgeneric
form is evaluated, one of three actions is taken (due to ensure-generic-function
):
- If a generic function of the given name already exists, the existing generic function object is modified. Methods specified by the current
defgeneric
form are added, and any methods in the existing generic function that were defined by a previous defgeneric
form are removed. Methods added by the current defgeneric
form might replace methods defined by defmethod
, defclass
, define-condition
, or defstruct
. No other methods in the generic function are affected or replaced.
- If the given name names an ordinary function, a macro, or a special operator, an error is signaled.
- Otherwise a generic function is created with the methods specified by the method definitions in the
defgeneric
form.
7.6.2 Introduction to Methods
When a method-defining form is evaluated, a method object is created and one of four actions is taken:
- If a generic function of the given name already exists and if a method object already exists that agrees with the new one on parameter specializers and qualifiers, the new method object replaces the old one. For a definition of one method agreeing with another on parameter specializers and qualifiers, see Section 7.6.3 (Agreement on Parameter Specializers and Qualifiers).
- If a generic function of the given name already exists and if there is no method object that agrees with the new one on parameter specializers and qualifiers, the existing generic function object is modified to contain the new method object.
- If the given name names an ordinary function, a macro, or a special operator, an error is signaled.
- Otherwise a generic function is created with the method specified by the method-defining form.
The definition of ensure-generic-function
:
If function-name specifies a generic function that has a different value for the :lambda-list
argument, and the new value is congruent with the lambda lists of all existing methods or there are no methods, the value is changed; otherwise an error is signaled.
If function-name specifies a generic function that has a different value for the :generic-function-class
argument and if the new generic function class is compatible with the old, change-class
is called to change the class of the generic function; otherwise an error is signaled.
If function-name specifies a generic function that has a different value for the :method-class
argument, the value is changed, but any existing methods are not changed.
You also have add-method
and remove-method
.
As you can see, generic functions retain their identify between defmethod
definitions, and even between defgeneric
definitions. Generic functions are mutable in Common Lisp.
In Julia, you can read the following from the documentation:
Defining Methods
To define a function with multiple methods, one simply defines the function multiple times, with different numbers and types of arguments. The first method definition for a function creates the function object, and subsequent method definitions add new methods to the existing function object.
As you can see, functions objects are mutable in Julia.
This says nothing about all other multiple dispatch languages. You can invent a multiple dispatch language right now just for the purpose of showing you can do it with immutability, e.g. adding methods would return a new function similar to the previous function but with the added method. Or a language where functions are generated statically at compile-time, such that you can't change it at runtime in any way, not even to add or remove methods.