6.11 Object, Class, and Interface Utilities (original) (raw)
6.11 Object, Class, and Interface Utilities🔗ℹ
Returns #t if v is an object, #f otherwise.
Examples:
Returns #t if v is a class, #f otherwise.
Examples:
Returns #t if v is an interface, #f otherwise.
Examples:
Returns #t if v is a generic, #f otherwise.
Examples:
Determines whether a and b were returned from the same call to new or not. If the two objects have fields, this procedure determines whether mutating a field of one would change that field in the other.
This procedure is similar in spirit toeq? but also works properly with contracts (and has a stronger guarantee).
Examples:
Like object=?, but accepts #f for either argument and returns #t if both arguments are #f.
Examples:
Added in version 6.1.1.8 of package base.
Returns the hash code for o that corresponds to the equality relation object=?.
Added in version 7.1.0.6 of package base.
Returns a vector representing object that shows its inspectable fields, analogous to struct->vector.
Examples:
> (object->vector (new object%)) '#(object:object% ...) '#(object:eval:113:0 ...)
(class->interface class) → interface? class : class?
Returns the interface implicitly defined by class.
Example:
(object-interface object) → interface? object : object?
Returns the interface implicitly defined by the class ofobject.
Example:
Returns #t if v is an instance of a classtype or a class that implements an interface type,#f otherwise.
Examples:
Returns #t if v is a class derived from (or equal to) cls, #f otherwise.
Examples:
Returns #t if v is a class that implementsintf, #f otherwise.
Examples:
Returns #t if v is an interface that extendsintf, #f otherwise.
Examples:
Returns #t if intf (or any of its ancestor interfaces) includes a member with the name sym, #fotherwise.
Examples:
Returns a list of symbols for the method names in intf, including methods inherited from superinterfaces, but not including methods whose names are local (i.e., declared withdefine-local-member-name).
Examples:
Returns #t if object has a method named symthat accepts cnt arguments, #f otherwise.
Examples:
Returns a list of all of the names of the fields bound inobject, including fields inherited from superinterfaces, but not including fields whose names are local (i.e., declared withdefine-local-member-name).
Examples:
Returns two values, analogous to the return values of struct-info:
- class: a class or #f; the result is#f if the current inspector does not control any class for which the object is an instance.
- skipped?: #f if the first result corresponds to the most specific class of object, #totherwise.
(class-info class) class : class?
Returns seven values, analogous to the return values of struct-type-info:
- name: the class’s name as a symbol;
- field-cnt: the number of fields (public and private) defined by the class;
- field-name-list: a list of symbols corresponding to the class’s public fields; this list can be larger than field-cntbecause it includes inherited fields;
- field-accessor: an accessor procedure for obtaining field values in instances of the class; the accessor takes an instance and a field index between 0 (inclusive) and field-cnt (exclusive);
- field-mutator: a mutator procedure for modifying field values in instances of the class; the mutator takes an instance, a field index between 0 (inclusive) and field-cnt (exclusive), and a new field value;
- super-class: a class for the most specific ancestor of the given class that is controlled by the current inspector, or #f if no ancestor is controlled by the current inspector;
- skipped?: #f if the sixth result is the most specific ancestor class, #t otherwise.
#:extra-constructor-name make-exn:fail:object)
Raised for class-related failures, such as attempting to call a method that is not supplied by an object.
Adds a seal to a given class keyed with the symbol key. The given unsealed-inits, unsealed-fields, andunsealed-methods list corresponding class members that are unaffected by sealing.
When a class has any seals, the inst-proc procedure is called on instantiation (normally, this is used to raise an error on instantiation) and the member-proc function is called (again, this is normally used to raise an error) when a subclass attempts to add class members that are not listed in the unsealed lists.
The inst-proc is called with the class value on which an instantiation was attempted. The member-proc is called with the class value and the list of initialization argument, field, or method names.
(class-unseal class key wrong-key-proc) → class? class : class? key : symbol? wrong-key-proc : (-> class? any)
Removes a seal on a class that has been previously sealed with theclass-seal function and the given key.
If the unseal removed all of the seals in the class, the class value can be instantiated or subclassed freely. If the given class value does not contain or any seals or does not contain any seals with the given key, the wrong-key-proc function is called with the class value.