Ok; that manual section is a little terse about how a punter like me should go about doing things whilst insisting on the idea of "changing fields in objects". I'm sure people have been here before, and I wonder if there's a "standard solution" somewhere?
My first intuition is that this object concept of mine should be implemented by passing around "symbolic references" rather than actual objects, and then have global support functions to
a) "create" an actual object (and get its symbolic reference),
b) to get the value of a field (by index) given a symbolic reference,
c) and to set (change!) the value of a field (by index) given a symbolic reference.
That would render my example to be as follows:
Code: Select all
(context 'One)
(define (One:One v)
(create 'One v))
(define (put v)
(setv (self) 1 v))
(context 'Two)
(define (Two:Two one x)
(:put one x)
(create 'Two one x))
(context MAIN)
(constant 'uno (One "A"))
(constant 'duo (Two uno "B"))
(println "uno=" uno " of "One:objects)
(println "duo=" duo " of " Two:objects)
With a resulting print out of
Code: Select all
uno=(One 0) of (("One" "B"))
duo=(Two 0) of (("Two" (One 0) "B"))
Thus, a symbolic reference, such as (One 0) is essentially an index into the table One:objects of actual One objects, as maintained by the global functions, and likewise for (Two 0).
I suppose, by that kind of approach I'll get my OO without hoops, except for that arms-length access to the actual objects. But I guess it might accrue unused objects in the tables.
Anyone having experience in this? Maybe even good implementations of my "create", "getv" and "setv" functions?