If the preceding sections are clear, then the creation of class instances such as aPoint and abPoint should be straightforward. To summarize:
> Point-class #procedure >
For example if we have a class definition called My-class, the Scheme entity My-class is a procedure that constructs and then returns a new instance of that class. If we have class parameters in our definition we simply provide corresponding arguments to the construction function. We did this with Point-class when we provide the initial x and y values.
Note that an instance is just another Scheme entity (in fact it is represented as a list) and thus can be passed to procedures and stored in data structures. In the Point-class example we simply created two instances using define:
(define aPoint (Point-class 2 4))
We could also store point objects in a list. For example try out the following:
> (define two-points-list (list (Point-class 0 0) (Point-class 0 0))) > (call location? (car two-points-list)) (0 0) > (call moveTo (cadr two-points-list) 19 45) (19 45)
do? Why might this be useful?(map (lambda (obj) (call moveRel obj 3 4)) two-points-list)
(call METHOD-NAME OBJECT-NAME ARG1 ARG2 ... ARGN)
where METHOD-NAME is the method to be called, OBJECT is an instance of a class and ARG1 ARG2 ... ARGN are the expressions providing values that are passed to the method.