Next section: 9. CollectionsThe seal generic form
There is also a seal generic top-level form, with the following syntax: seal generic function ( type, ... );The function must be a module variable that refers to a generic function.
The types must be expressions that evaluate to instances of <type>. The number of types must be the same as the number of required arguments accepted by the function.
A seal generic form in a library L for a generic function G with types T1...Tn imposes the following constraints on programs:
- A method M which is congruent to G and which is not an explicitly known method in L may be added to G if and only if at least one of the specializers for M is disjoint from the corresponding type in the sealing form.
- A method M may be removed from G if and only if at least one of the specializers for M is disjoint from the corresponding type in the sealing form.
- A class C with direct superclasses D1...Dm and which is not an explicitly known class in L may be created if and only if
- none of the classes D1...Dm are subtypes of any of the types T1...Tn in the sealing form, or
- for every method M in G with specializers S1...Sn, if there exists an i such that Si is disjoint from Ti, then M must satisfy condition (1) below, otherwise M must satisfy condition (2) below.
- There exists an i such that Si is disjoint from Ti and such that there do not exist j and k such that Dj is a subtype of Si and Dk is a subtype of Ti.
- There do not exist i, j, and k such that Dj and Dk are subtypes of Ti, Dj is disjoint from Dk, Dj is a subtype of Si, and Dk is not a subtype of Si.
Abbreviations for seal generic
define sealed method defines a normal method and then seals the generic function for the types that are the specializers of the method. define sealed method is a convenient abbreviation for the seal generic form.
The sealed slot option to define class defines a normal slot and then seals the getter generic function for the class, and seals the setter generic function, if there is one, on <object> and the class. The sealed slot option to define class is a convenient abbreviation for the seal generic form.