Instance creation and slot access

Creation of an instanceinstance of a previously defined class can be done with the makemake 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


\begin{scheme}
(define c (make <complex>))
\end{scheme}

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-refslot-ref and the slot-set!slot-set! primitives. Slot-set! primitive permits to set the value of an object slot and slot-ref permits to get its value.


\begin{scheme}
(slot-set! c 'r 10)
(slot-set! c 'i 3)
(slot-ref c 'r) \lev 10
(slot-ref c 'i) \lev 3
\end{scheme}

Using the 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


\begin{scheme}
(describe c)
\end{scheme}
will print the following informations on the standard output:
\begin{scheme}
\sharpsign[<complex> 122398] is an instance of class <complex>
Slots are:
r = 10
i = 3
\end{scheme}