IOS Defined Classes¶
IOS defines a number of classes, several of which are used internally to define the meta-object protocol (MOP).
MOP Classes¶
The MOP classes are used to define the implementation of the (user-level) use of classes and are (necessarily) circular in definition.
Most classes have a MOP class of <class>
– including <class>
itself.
MOP classes are distinct from the normal super-class element in a class definition. MOP classes do have super-classes as seen in this table:
class |
super-class |
description |
---|---|---|
|
(none) |
the root |
|
|
the ancestor of all objects |
|
|
the ancestor of all invokable classes |
|
|
the MOP class of generics |
|
|
|
|
|
Builtin Classes¶
The regular Idio types are represented by classes with a
super-class <builtin-class>
(itself with a super-class of
<top>
).
The builtin classes include:
<C/char>
<C/double>
<C/float>
<C/int>
<C/long>
<C/longdouble>
<C/longlong>
<C/pointer>
<C/schar>
<C/short>
<C/uchar>
<C/uint>
<C/ulong>
<C/ulonglong>
<C/ushort>
<array>
<bignum>
<bitset>
<constant>
<continuation>
<fixnum>
<handle>
<hash>
<keyword>
<module>
<pair>
<string>
<struct-instance>
<struct-type>
<symbol>
<unicode>
<closure>
and <primitive>
are invokable classes.
Class Predicates¶
- function object/class? o¶
test if o is a class
- Param o:
object to test
- Return:
#t
if o is a class,#f
otherwise
- function object/generic? o¶
test if o is a generic
- Param o:
object to test
- Return:
#t
if o is a generic,#f
otherwise
- function object/method? o¶
test if o is a method
- Param o:
object to test
- Return:
#t
if o is a method,#f
otherwise
- function object/instance? o¶
test if o is a instance
- Param o:
object to test
- Return:
#t
if o is a instance,#f
otherwise
Class Constructors¶
- function object/define-class name [supers [slots]]¶
define-template: (define-class name & args) (x e)
define a new class, name, with optional super-classes and slots
- Param name:
name of the class
- Type name:
symbol
- Param supers:
super-classes of the new class, defaults to
#n
- Type supers:
list of symbols, a symbol or
#n
, optional- Param slots:
slots of the new class, defaults to
#n
- Type slots:
see below, optional
- Return:
class
- Rtype:
instance
Additionally, the symbol name will be bound to the new class.
slots can each be a simple symbol, the slot’s name, or a list of a symbol, the slot’s name, and some slot options.
If a slot is declared as:
a simple symbol then it has no slot options
a list then, in addition to any slot options given, a slot option of
:initarg
with a keyword value of:slot-name
is added if no:initarg
is otherwise given
Slot options include:
:initarg keyword
Subsequently,
keyword arg
can be passed to make-instance to set the slot’s value toarg
:initform func
Here, if no
:initarg
overrides thenfunc
is applied to the initargs passed to make-instance to get the default slot value instead of a “default slot value” function which returns#f
.func
should expect to be passed any number of arguments.
- Example:
Idio> define-class A #<CLASS A> Idio> define-class B A #<CLASS B> Idio> define-class C (B) #<CLASS C> Idio> define-class D #n a b c #<CLASS D>
- function object/make-class name supers slots¶
create a new class, name, with super-classes and slots
- Param name:
name of the class
- Type name:
symbol
- Param supers:
super-classes of the new class
- Type supers:
list of class instances
- Param slots:
slots of the new class
- Type slots:
list of symbols
- Return:
new class
- Rtype:
instance
make-class
would not normally be called by users.See also
- function object/define-generic name [doc]¶
define-template: (define-generic name & args) (x e)
define a new generic function, name, with optional documentation
- Param name:
name of the generic function
- Type name:
symbol
- Param doc:
documentation string, defaults to
#n
- Type doc:
string or
#n
, optional- Return:
generic function
- Rtype:
instance
Additionally, the symbol name will be bound to the new generic function.
define-generic
would not normally be called by users as generic functions are implicitly created through the use of define-method.See also
- function object/define-method name [specialized-formals] [docstr] body ...¶
define-template: (define-method args & body) (x e)
define a new method for the generic function, name. The generic function name will be created if it does not already exist.
The specialized-formals take the form
[specialized-formal ...]
andspecialized-formal
can take either the form(name class)
or the formname
which implies a class of<object>
.If a documentation string is supplied then it will be used for the documentation for the generic function name unless name already exists.
- Example:
These two declarations are equivalent:
define-method (foo/1 arg) ... define-method (foo/1 (arg <object>)) ...
Similarly for multiple arguments:
define-method (foo/2 arg1 arg2) ... define-method (foo/2 (arg1 <object>) arg2) ... define-method (foo/2 (arg1 <object>) (arg2 <object>)) ... define-method (foo/2 arg1 (arg2 <object>)) ...
- function object/make-instance cl [initargs]¶
create an instance of class cl using initargs
- Param cl:
class
- Type cl:
instance
- Param initargs:
initialization arguments
- Type initargs:
list
- Return:
instance
- Rtype:
instance
initargs should be a series of
keyword arg
pairs where the keyword and argument are dependent on the class of cl.
Class Accessors¶
- function object/class-name cl¶
return the name of class cl
- Param cl:
class
- Type cl:
instance
- Return:
name of class cl
- function object/class-direct-supers cl¶
return the direct-supers of class cl
- Param cl:
class
- Type cl:
instance
- Return:
direct supers of class cl
- function object/class-direct-slots cl¶
return the direct-slots of class cl
- Param cl:
class
- Type cl:
instance
- Return:
direct slots of class cl
- function object/class-cpl cl¶
return the cpl of class cl
- Param cl:
class
- Type cl:
instance
- Return:
cpl of class cl
- function object/class-slots cl¶
return the slots of class cl
- Param cl:
class
- Type cl:
instance
- Return:
slots of class cl
- function object/class-nfields cl¶
return the nfields of class cl
- Param cl:
class
- Type cl:
instance
- Return:
nfields of class cl
- function object/class-getters-n-setters cl¶
return the getters-n-setters of class cl
- Param cl:
class
- Type cl:
instance
- Return:
getters-n-setters of class cl
- function object/class-of o¶
return the class of o
- Param o:
object to query
- Return:
class of o
Generic Accessors¶
- function object/generic-name gf¶
return the name of generic function gf
- Param gf:
generic function
- Type gf:
instance
- Return:
name of generic function gf
- function object/generic-documentation gf¶
return the documentation of generic function gf
- Param gf:
generic function
- Type gf:
instance
- Return:
documentation of generic function gf
- function object/generic-methods gf¶
return the methods of generic function gf
- Param gf:
generic function
- Type gf:
instance
- Return:
methods of generic function gf
Method Accessors¶
- function object/method-generic-function m¶
return the generic function of method function m
- Param m:
method function
- Type m:
instance
- Return:
generic function of method function m
- function object/method-procedure m¶
return the procedure of method function m
- Param m:
method function
- Type m:
instance
- Return:
procedure of method function m
- function object/method-specializers m¶
return the specializers of method function m
- Param m:
method function
- Type m:
instance
- Return:
specializers of method function m
- function object/%set-instance-proc! gf proc¶
set the instance procedure of gf to proc
- Param gf:
generic function to modify
- Type gf:
generic
- Param proc:
function to use
- Type proc:
function
- Return:
#<unspec>
Last built at 2025-02-05T07:10:32Z+0000 from 62cca4c (dev) for Idio 0.3.b.6