Up: descriptors other   [Contents][Index]


4.4.1 Interface type descriptors

The following syntactic bindings are exported by the library (vicare system type-descriptors).

Record Type: <interface-type-descr>

Name of type descriptors representing interfaces. It has the following fields:

type-name

A symbol representing the name of this interface type.

uid

A symbol acting as unique identifier associated to this type descriptor.

parent-type-descriptor

An instance of <interface-type-descr> representing the parent of this interface–type; #f if this interface–type has no parent.

implemented-interface-uids

A list of symbols representing the UIDs of the interfaces implemented by this interface–type.

method-prototype-names

A list of symbols representing the names of public methods that must be provided by object–types implementing this interface.

method-retriever

A function that retrieves method implementation functions given the name of a method as symbol.

Function: make-interface-type-descr type-name uid parent-type-descriptor implemented-interface-uids method-prototype-names method-retriever

Build and return a new instance of <interface-type-descr>.

Function: interface-type-descr? obj

Return #t if obj is an instance of <interface-type-descr>; otherwise return #f.

Function: interface-type-descr.type-name des
Function: interface-type-descr.uid des
Function: interface-type-descr.parent-type-descriptor des
Function: interface-type-descr.implemented-interface-uids des
Function: interface-type-descr.method-prototype-names des
Function: interface-type-descr.method-retriever des

Accessors for the fields of <interface-type-descr> instances.

Function: object-type-implements-interface? interface-uid descr

The argument descr must be an object–type’s run–time descriptor. Return #t if the object–type implements the interface–type whose UID is interface-uid; otherwise return #f.

Usage example, a record–type implements an interface–type:

(define-interface-type <IOne>
  (nongenerative dummy:<IOne>)
  (method-prototype doit
    (lambda (<string>) => (<number>))))

(define-record-type <blue>
  (implements <IOne>)
  (method ({doit <number>} {S <string>})
    1))

(object-type-implements-interface?
  'dummy:<IOne>
  (record-type-descriptor <blue>))
⇒ #t

(object-type-implements-interface?
  (car (type-unique-identifiers <IOne>))
  (record-type-descriptor <blue>))
⇒ #t

(define O
  (new <blue>))

(is-a? O <IOne>)                                ⇒ #t
(is-a? (cast-signature (<top>) O) <IOne>)       ⇒ #t

Another usage example, a record–type implements an interface–type and its parent:

(define-interface-type <IOne>
  (method-prototype one
    (lambda (<string>) => (<number>))))

(define-interface-type <ITwo>
  (parent <IOne>)
  (method-prototype two
    (lambda (<string>) => (<number>))))

(define-record-type <blue>
  (implements <ITwo>)
  (method ({one <number>} {S <string>})
    1)
  (method ({two <number>} {S <string>})
    1))

(object-type-implements-interface?
  (car (type-unique-identifiers <IOne>))
  (record-type-descriptor <blue>))
⇒ #t

(object-type-implements-interface?
  (car (type-unique-identifiers <ITwo>))
  (record-type-descriptor <blue>))
⇒ #t

(define O
  (new <blue>))

(is-a? O <IOne>)        ⇒ #t
(is-a? O <ITwo>)        ⇒ #t

(is-a? (cast-signature (<top>) O) <IOne>)       ⇒ #t
(is-a? (cast-signature (<top>) O) <ITwo>)       ⇒ #t

Up: descriptors other   [Contents][Index]