MOP

See the Guide for an introduction to Gerbil's object system. These procedures provide the meta-object protocol.

MOP Procedures

class-type?

(class-type? o) -> boolean

Returns true if o is a standard class.

class-type=?

(class-type=? klass other-klass) -> boolean

  klass, other-klass := class

Returns true if both classes have the same type id.

class-type-final?

(class-type-final? klass) -> boolean

  klass := class

Returns true if a class is final.

class-type-struct?

(class-type-struct? klass) -> boolean

  klass := class

Returns true if a class has the struct property.

class-type-sealed?

(class-type-sealed? klass) -> boolean

  klass := class

Returns true if a class has been sealed.

class-type-metaclass?

(class-type-metaclass? klass) -> boolean

  klass := class

Returns true if a class has the metaclass property.

class-type-system?

(class-type-system? klass) -> boolean

  klass := class

Returns true if a class has the metaclass property.

class-type-id

(class-type-id klass)

Returns the type id of a class

class-type-name

(class-type-name klass)

Returns the name of a class

class-type-super

(class-type-super klass)

Returns the super class of a class; applicable to struct only.

class-type-flags

(class-type-flags klass)

Returns the flags of a class.

class-type-fields

(class-type-fields klass)

Returns the field vector of a class

class-type-precedence-list

(class-type-precedence-list klass)

Returns the precedence list of a class

class-type-slot-vector

(class-type-slot-vector klass)

Returns the slot vector of a class

class-type-slot-table

(class-type-slot-table klass)

Returns the slot table of a class

class-type-properties

(class-type-properties klass)

Returns the properties of a class, as an associative list

class-type-constructor

(class-type-constructor klass)

Returns the constructor method id of a class or #f if none

class-type-methods

(class-type-methods klass)

Returns a symbol table with the direct methods of a class or #f if it has no direct methods.

class-type-slot-list

(class-type-slot-list klass)

Returns the list of slots of a class, as laid out in the object.

class-type-field-count

(class-type-field-count klass)

Returns the number of fields in a class

class-type-seal!

(class-type-seal! klass)

Sets the sealed flag on a class.

subclass?

(subclass? maybe-sub-class maybe-super-class)

Returns true if a class is a subclass of another class.

substruct?

(substruct? maybe-sub-struct maybe-super-struct)

Returns true if a class is a substruct of a nother class

make-class-type

(make-class-type id name direct-supers direct-slots properties constructor) -> type-descriptor

  id             := symbol; the unique type id
  name           := symbol; the possibly not unique source type name used when displaying the class
  direct-supers  := list of type-descriptors or #f; super types
  direct-slots   := list of symbols; class slot names
  properties     := alist; type properties (NB: not a plist)
  constructor    := symbol or #f; id of constructor method

alist elements:
 (transparent: . boolean) ; controls whether the object is transparent
                            in equality and printing
 (final: . boolean)       ; controls whether the class if final
 (struct: . boolean)      ; controls whether the class is a struct
 (print: slot ...)        ; list of printable slots, or boolean
 (equal: slot ...)        ; list of equality comparable slots, or boolean

Creates a new class.

make-class-predicate

(make-class-predicate klass) -> procedure

  klass := class

Creates a class instance predicate for instances of klass.

make-class-slot-accessor

(make-class-slot-accessor klass slot) -> procedure

  klass := class
  slot  := symbol

Creates a slot accessor for slot.

make-class-slot-mutator

(make-class-slot-mutator klass slot) -> procedure

  klass := class
  slot  := symbol

Creates a slot mutator for slot.

make-class-slot-unchecked-accessor

(make-class-slot-unchecked-accessor klass slot) -> procedure

  klass := class
  slot  := symbol

Like make-class-slot-accessor, but creates an unchecked accessor.

make-class-slot-unchecked-mutator

(make-class-slot-unchecked-mutator klass slot)  -> procedure

  klass := class
  slot  := symbol

Like make-class-slot-mutator, but creates an unchecked mutator.

direct-instance?

(direct-instance? klass obj) -> bool

Returns true if obj is an immediate instance of klass.

struct-instance?

(struct-instance? klass obj)

Returns true if obj is a struct instance of klass.

This procedures checks the inheritance chain of obj's type; obj is a struct instance of klass if it is an object and its type is includes klass in its inheritance chain.

class-instance?

(class-instance? klass obj)

Returns true if obj is a class instance of klass.

This procedures checks the precedence list of obj's class; obj is a class instance of klass if it is an object and its class includes klass in its precedence list.

make-object

(make-object klass k) -> object

  klass := class; the new objects's class
  k     := fixnum; the field count in the object, including the class

Creates an object with class klass and k fields, initialized with #f.

object?

(object? o) -> boolean

Returns true if o is a standard object instance.

object-type

(object-type obj)

Returns the class of a standard object; obj should be a standard object instance.

object-fill!

(object-fill! obj fill)

  obj  := object
  fill := any

Initializes an object obj with a value of fill

new-instance

(new-instance klass)

  klass := class

Creates a new instance of klass without invoking the constructor. All slots are initialized with #f.

make-instance

(make-instance klass . args)

  klass := class

Creates a new instance of klass and initializes it with the appropriate constructor with arguments args.

struct-instance-init!

(struct-instance-init! obj . args)

  obj := object

Initializes obj by setting its fields to args from left to right. If there are more fields than arguments, then they are left uninitialized. It is an error if there are more arguments than fields in the object.

class-instance-init!

(class-instance-init! obj . args)

  obj := object

Initializes obj, using args as a plist of slot keywords/symbols and values. For every slot and value in the plist, the corresponding object slot is set to the value.

constructor-init!

(constructor-init! klass kons-id obj . args)

  klass := class
  kons-id := symbol; constructor method
  obj := object

Initializes obj by applying the constructor with id kons-id from the class klass.

struct-copy

(struct-copy obj)

Copies an object.

struct->list

(struct->list obj) -> list

  obj := object

Converts an object to a list, with the class in the car and the fields in order in the cdr.

class->list

(class->list obj) -> list

Converts an object to a list, with the class in the car and a plist of slots and values in the cdr.

slot-ref

(slot-ref obj slot [E]))

  obj  := object
  slot := symbol or keyword
  E    := procedure

Returns the value associated with slot slot in obj. If the object has no such slot, then E is invoked in tail position as (E obj slot). By default, this raises an error.

slot-set!

(slot-set! obj slot val [E])

  obj  := object
  slot := symbol or keyword
  val  := any
  E    := procedure;

Sets the value associated with slot slot in obj to val. If the object has no such slot, then E is invoked in tail position as (E obj slot). By default, this raises an error.

unchecked-slot-ref

(unchecked-slot-ref obj slot)

  obj  := object
  slot := symbol or keyword

Returns the value associated with slot slot in obj, without any checks.

This is an unsafe procedure.

unchecked-slot-set!

(unchecked-slot-set! obj slot val)

  obj  := object
  slot := symbol or keyword
  val  := any

Sets the value associated with slot slot in obj to val, without any checks.

This is an unsafe procedure.

call-method

(call-method obj id . args)

  obj  := any object
  id   := symbol; method id
  args := rest of arguments

Applies the method with id in obj to args, with the object itself as the first argument. Raises an error if the object has no such method bound.

method-ref

(method-ref obj id) -> procedure | #f

  obj := object
  id  := symbol; method id

Looks up the method with id in obj's class hierarchy.

checked-method-ref

(checked-method-ref obj id) -> procedure

  obj := object
  id  := symbol; method id

Like method-ref, but raises an error if the method is not found.

bound-method-ref

(bound-method-ref obj id) -> procedure | #f

  obj := object
  id  := symbol; method id

Looks up the method with id in obj's hierarchy and returns a procedure which applies the method currying the object.

checked-bound-method-ref

(checked-bound-method-ref obj id) -> procedure

  obj := object
  id  := symbol; method id

Like bound-method-ref, but raises an error if the method is not found.

direct-method-ref

(direct-method-ref klass obj id) -> procedure | #f

  klass := class
  id    := symbol; method id

Returns the (direct) binding of method with id in class klass.

find-method

(find-method klass obj id)

bind-method!

(bind-method! klass id proc [rebind? = #f])

  klass   := class
  id      := symbol; method id
  proc    := procedure; method implementation
  rebind? := boolean; allow method rebinding?

Binds proc as the method with id in class klass.

bind-specializer!

(bind-specializer! method-proc specializer)

  method      := procedure implementing a method
  specializer := procedure of two arguments,  that returns the specialized method

Binds a specializer procedure associated with a method. When a class is sealed or an interface instance prototype is created, the specializer is invoked with the concrete class and the specialized method table to generate a version of the method that is specialized for the concrete class.

seal-class!

(seal-class! klass)

  klass := class

Seals a class, which must be final. Sealing a class specializes and coalesces all methods in the hierarchy to the class' method table.

next-method

(next-method klass obj id) -> procedure | #f

  klass := type-descriptor or builtin record descriptor
  obj   := object
  id    := symbol; method id

Returns the next method in obj's hierarchy, following klass.

call-next-method

(call-next-method klass obj id . args) -> any

  klass := type-descriptor or builtin record descriptor
  obj   := object
  id    := symbol; method id

Invokes the next method in obj's hierarchy, following klass.

class-of

(class-of o) -> class

 o := any

Returns the class of an object or primitive value.

Predefined Classes

t::t

(def t::t ...)

The class of everything.

class::t

(def class::t ...)

The class of classes.

object::t

(def object::t ...)

The class of standard objects.

immediate::t

(defsystem-class immediate::t immediate ())

atom::t

(defsystem-class atom::t atom (immediate::t))

char::t

(defsystem-class char::t char (immediate::t))

boolean::t

(defsystem-class boolean::t boolean (immediate::t))

true::t

(defsystem-class true::t true (boolean::t atom::t))

false::t

(defsystem-class false::t false (boolean::t atom::t))

void::t

(defsystem-class void::t void (atom::t))

eof::t

(defsystem-class eof::t eof (atom::t))

special::t

(defsystem-class special::t special (atom::t))

number::t

(defsystem-class number::t number ())

real::t

(defsystem-class real::t real (number::t))

integer::t

(defsystem-class integer::t integer (real::t))

fixnum::t

(defsystem-class fixnum::t fixnum (integer::t immediate::t))

bignum::t

(defsystem-class bignum::t bignum (integer::t))

ratnum::t

(defsystem-class ratnum::t ratnum (real::t))

flonum::t

(defsystem-class flonum::t flonum (real::t))

cpxnum::t

(defsystem-class cpxnum::t cpxnum (number::t))

symbolic::t

(defsystem-class symbolic::t symbolic ())

symbol::t

(defsystem-class symbol::t symbol (symbolic::t))

keyword::t

(defsystem-class keyword::t keyword (symbolic::t))

list::t

(defsystem-class list::t list ())

pair::t

(defsystem-class pair::t pair (list::t))

null::t

(defsystem-class null::t null (list::t atom::t))

sequence::t

(defsystem-class sequence::t sequence ())

vector::t

(defsystem-class vector::t vector (sequence::t))

string::t

(defsystem-class string::t string (sequence::t))

hvector::t

(defsystem-class hvector::t hvector (sequence::t))

u8vector::t

(defsystem-class u8vector::t u8vector (hvector::t))

s8vector::t

(defsystem-class s8vector::t s8vector (hvector::t))

u16vector::t

(defsystem-class u16vector::t u16vector (hvector::t))

s16vector::t

(defsystem-class s16vector::t s16vector (hvector::t))

u32vector::t

(defsystem-class u32vector::t u32vector (hvector::t))

s32vector::t

(defsystem-class s32vector::t s32vector (hvector::t))

u64vector::t

(defsystem-class u64vector::t u64vector (hvector::t))

s64vector::t

(defsystem-class s64vector::t s64vector (hvector::t))

f32vector::t

(defsystem-class f32vector::t f32vector (hvector::t))

f64vector::t

(defsystem-class f64vector::t f64vector (hvector::t))

values::t

(defsystem-class values::t values ())

box::t

(defsystem-class box::t box ())

frame::t

(defsystem-class frame::t frame ())

continuation::t

(defsystem-class continuation::t continuation ())

promise::t

(defsystem-class promise::t promise ())

weak::t

(defsystem-class weak::t weak ())

foreign::t

(defsystem-class foreign::t foreign ())

procedure::t

(defsystem-class procedure::t procedure ())

return::t

(defsystem-class return::t return ())

time::t

(defshadow-class time::t () (macro-type-time))

thread::t

(defshadow-class thread::t () (macro-type-thread))

thread-group::t

(defshadow-class thread-group::t () (macro-type-tgroup))

mutex::t

(defshadow-class mutex::t () (macro-type-mutex))

condvar::t

(defshadow-class condvar::t () (macro-type-condvar))

port::t

(defshadow-class port::t () (macro-type-port))

object-port::t

(defshadow-class object-port::t (port::t) (macro-type-object-port))

character-port::t

(defshadow-class character-port::t (object-port::t) (macro-type-character-port))

byte-port::t

(defshadow-class byte-port::t (character-port::t) (macro-type-byte-port))

device-port::t

(defshadow-class device-port::t (byte-port::t) (macro-type-device-port))

vector-port::t

(defshadow-class vector-port::t (object-port::t) (macro-type-vector-port))

string-port::t

(defshadow-class string-port::t (character-port::t) (macro-type-string-port))

u8vector-port::t

(defshadow-class u8vector-port::t (byte-port::t) (macro-type-u8vector-port))

raw-device-port::t

(defshadow-class raw-device-port::t (port::t) (macro-type-raw-device-port))

tcp-server-port::t

(defshadow-class tcp-server-port::t (object-port::t) (macro-type-tcp-server-port))

udp-port::t

(defshadow-class udp-port::t (object-port::t) (macro-type-udp-port))

directory-port::t

(defshadow-class directory-port::t (object-port::t) (macro-type-directory-port))

event-queue-port::t

(defshadow-class event-queue-port::t (object-port::t) (macro-type-event-queue-port))

table::t

(defshadow-class table::t () (macro-type-table))

readenv::t

(defshadow-class readenv::t () (macro-type-readenv))

writeenv::t

(defshadow-class writeenv::t () (macro-type-writeenv))

readtable::t

(defshadow-class readtable::t () (macro-type-readtable))

processor::t

(defshadow-class processor::t () (macro-type-processor))

vm::t

(defshadow-class vm::t () (macro-type-vm))

file-info::t

(defshadow-class file-info::t () (macro-type-file-info))

socket-info::t

(defshadow-class socket-info::t () (macro-type-socket-info))

address-info::t

(defshadow-class address-info::t () (macro-type-address-info))

System Object Predicates

special?

(special? o) -> boolean

sequence?

(sequence? o) -> boolean

hvector?

(hvector? o) -> boolean

weak?

(weak? o) -> boolean

object-port?

(object-port? o) -> boolean

character-port?

(character-port? o) -> boolean

byte-port?

(byte-port? o) -> boolean

character-port?

(character-port? o) -> boolean

device-port?

(device-port? o) -> boolean

vector-port?

(vector-port? o) -> boolean

string-port?

(string-port? o) -> boolean

u8vector-port?

(u8vector-port? o) -> boolean

raw-device-port?

(raw-device-port? o) -> boolean

tcp-server-port?

(tcp-server-port? o) -> boolean

udp-port?

(udp-port? o) -> boolean

directory-port?

(directory-port? o) -> boolean

event-queue-port?

(event-queue-port? o) -> boolean

readenv?

(readenv? o) -> boolean

writenv?

(writenv? o) -> boolean

vm?

(vm? o) -> boolean