[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
10.8 Introspection
Bigloo provides the programmer with some object introspection facilities.
See section see section Object library for information on classes and
objects handling. Introspection facilities are, by default, available
for all classes. However, in order to shrink the code size generation,
it may be useful to disable class introspection. This decision can be
taken on a per class basis (i.e., one class may be provided with
introspection facilities while another one is not). The compiler
option -fno-reflection
(see Chapter Compiler description) prevents the
compiler to generate the code required for introspecting the classes
defined in the compiled module.
- bigloo procedure: class-fields class
Returns the a description of the fields of class. This description is a list of field descriptions where each field description can be accessed by the means of the following library functions. The fields are those directly defined in class. That is
class-fields
does not return fields defined in super classes of class.
- bigloo procedure: class-all-fields class
Returns the a description of the fields of class. This description is a list of field descriptions where each field description can be accessed by the means of the following library functions. By contrast with
class-fields
, this function returns fields that are also defined in the super classes of class. in th
- bigloo procedure: find-class-field class symbol
Returns the field named symbol from class class. Returns
#f
is such a field does not exist.
- bigloo procedure: class-field? obj
Returns #t if obj is a class field descriptor. Otherwise returns #f.
- bigloo procedure: class-field-accessor field
Returns a procedure of one argument. Applying this function to an object returns the value of the field described by field.
- bigloo procedure: class-field-mutable? field
Returns
#t
if the described field is mutable and#f
otherwise.
- bigloo procedure: class-field-mutator field
Returns a procedure of two arguments. Applying this function to an object changes the value of the field described by field. It is an error to apply
class-field-mutator
to an immutable field.
- bigloo procedure: class-field-info field
Returns the information associated to field (this the class declaration
info
attribute).
For means of an example, here is a possible implementation of the
equal?
test for objects:
(define (object-equal? obj1 obj2) (define (class-field-equal? fd) (let ((get-value (class-field-accessor fd))) (equal? (get-value obj1) (get-value obj2)))) (let ((class1 (object-class obj1)) (class2 (object-class obj2))) (cond ((not (eq? class1 class2)) #f) (else (let loop ((fields (class-fields class1)) (class class1)) (cond ((null? fields) (let ((super (class-super class))) (if (class? super) (loop (class-fields super) super) #t))) ((class-field-equal? (car fields)) (loop (cdr fields) class)) (else #f)))))))
- bigloo procedure: class-creator class
Returns the creator for class. The creator is a function for which the arity depends on the number of slots the class provides (see Section see section Creating and accessing objects).
When an instance is allocated by the means of the
class-creator
, as for direct instantiation, the class constructor is automatically invoked. Example:(module foo (main main) (static (class c1 (c1-constructor)))) (define c1-constructor (let ((count 0)) (lambda (inst) (set! count (+ 1 count)) (print "creating instance: " count) inst))) (define (main argv) (let ((o1 (instantiate::c1)) (o2 (instantiate::c1)) (o3 ((class-creator c1)))) 'done)) -| creating instance: 1 creating instance: 2 creating instance: 3
- bigloo procedure: class-predicate class
Returns the predicate for class. This predicate returns
#t
when applied to object of type class. It returns#f
otherwise.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.