Instance creation and slot access

Creation of an instancendexfile(index-entry "instance" "rm" main ) of a previously defined class can be done with the makendexfile(index-entry "make" "tt" aux ) procedure. This procedure takes one mandatory parameter which is the class of the instance which must be created and a list of optional arguments. Optional arguments are generally used to initialize some slots of the newly created instance. For instance, the following form

$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(define c (make <complex>))

will create a new <complex> object and will bind it to the c Scheme variable.

Accessing the slots of the new complex number can be done with the slot-refndexfile(index-entry "slot-ref" "tt" aux ) and the slot-set!ndexfile(index-entry "slot-set!" "tt" aux ) primitives. Slot-set! primitive permits to set the value of an object slot and slot-ref permits to get its value.

$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(slot-set! c 'r 10)(slot-set! c 'i 3)(slot-ref c 'r) 10(slot-ref c 'i) 3

Using the ndexfile(index-entry "describe" "tt" aux )describe generic function is a simple way to see all the slots of an object at one time: this function prints all the slots of an object on the standard output. For instance, the expression

$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(describe c)
will print the following informations on the standard output: $\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`

          gobblecr#[<complex> 122398] is an instance of class <complex>Slots are:      r = 10     i = 3