4 ms·
> So the example manages to evade any need for encapsulation. In Scheme and many other lisps there is no difference between “objects” and “records” and “fields
by Blikkentrekker 6y ago
> So the example manages to evade any need for encapsulation.
In Scheme and many other lisps there is no difference between “objects” and “records” and “fields” and “methods”.
Defining a record with a number of fields also defines accessor functions, such that:
(define-record point
(fields (mutable x) (mutable y)))
defines the following procedures:
make-point
point?
point-x
point-y
point-set-x!
point-set-y!
All these names can optionally be changed to something else.
Encapsulation is simply enforced by not exporting any of these procedures from the module wherein they are defined.
Any arbitrarily more complicated functions can be built on top of these which can be exported.
As such, there is no meaningful difference any more between an object and a record, there is no special “dot notation” for field access and method calls, and normal procedure calls are used. This follows the general lisp design principle of avoiding special syntax as much as possible and using ordinary procedure calls for everything. There is no special “subscript notation” for `vector[i]` either, and `(vector-ref vector i)` is used instead.