It is less confusing if we describe the code in original
object oriented terminology (all in italic font). The following function call is called a
message call in OO:
:move is the
message sent to the
object aCircle and 10 and 20 are the
message parameters, only two of them in this example. In OO Java or JavaScript you would write aCircle.move(10, 20).
The
object aCircle
encapsulates the
object data and the
methods how to process the data. So when we receive the call, we really are inside the
object aCircle and can refer to it with (self). There are only two parameters in the :move
message, in this case 10 and 20 for the dx and dy
method parameters.
The function (self) returns the
object with the
Class Id at index 0 and values for x-position, y-position and radius at index 1,2 and 3. In out example (self) is aCircle, the receiver of the
message
Code: Select all
(define (Circle:move dx dy)
(inc (self 1) dx)
(inc (self 2) dy))
Because all the shapes of
Class Circle use the same methods, we don't have to carry them around in each
object instance of that
Class, but can just point to with a
Class Id, which is the first thing in the aCircle
object (Circle 1 2 3).
Note that :move is not the same thing as Circle:move. :move is the
message sent, and Circle:move is the
method processing the
message received by the
object aCircle which is an
instantiation of
Class Circle. The
message :move is
polymorph and depending on the
object Class it may point to different
methods, there could also be a Rectangle:move
method or Triangle:move
method.