Thank you for this reference, Peter. I didn't know about the Chicken
module before.
The only difference seems to be in fact just in `make-locative`. But
this is not problematic because the first argument of my
`make-locative` has to be a procedure, while the first argument of
Chicken's `make-locative` must be a non-procedure.
So an implementation can easily support both versions in one
procedure. More importantly, if one version is mistaken for the other,
it won't go silent.
What I find interesting is Chicken's `(make-weak-locative CONTAINER
INDEX)'. To my proposal, I could add `(make-weak-locative KEY
LOCATIVE)` (again with no problematic clash!) defined through
something like:
(define make-weak-locative
(lambda (key loc)
(define eph (make-ephemeron key loc))
(make-ephemeron-locative eph)))
(define make-ephemeron-locative
(lambda (eph)
(define who 'make-ephemeron-locative)
(define locative
(lambda ()
(define loc (ephemeron-datum eph))
(when (ephemeron-broken? eph)
(assertion-violation who "location garbage collected" eph))
loc))
(make-locative
(lambda ()
(location-ref (location)))
(lambda obj*
(apply location-set! (location) obj*)))))
Here, I used the procedures of SRFI 124. KEY is a Scheme object that
controls the availability of the locative. A typical use would be
(define vec (vector 1 2 3))
(define weak-loc (make-weak-locative vec (make-vector-locative vec 0)))
(define first (location-ref weak-loc)) ; first <- 1
(reference-barrier vec)
(define second (location-ref weak-loc)) ; may raise an assertion violation
Am Fr., 19. Aug. 2022 um 14:02 Uhr schrieb Peter Bex <xxxxxx@more-magic.net>:
>
> On Fri, Aug 19, 2022 at 12:53:57PM +0200, Marc Nieper-Wißkirchen wrote:
> > Your extensive knowledge is always very helpful, John!
> >
> > So, let us call the objects "locatives" instead. This also has the
> > advantage that the getter can be reasonably named "locative-ref" as would
> > be custom in Scheme.
>
> Looks like your proposal is quite similar to what we have in CHICKEN.
> I would argue to have a look at our API first, since the proposal has
> some API parts that have the same names as CHICKEN's, but are
> incompatible in their definition.
>
> https://wiki.call-cc.org/man/5/Module%20(chicken%20locative)
>
> From a quick scan, at least make-locative is different.
>
> Cheers,
> Peter