[M3devel] REFANY-keyed tables?

JC Chu jcchu at acm.org
Sun Mar 2 16:00:25 CET 2014


> You can't apply ^ to REFANY.

That was a mistake on my part.  Let me rephrase my worry as follows, where st(r) denotes the storage location pointed to by the reference r.

  1. x, y: REF T, where T has an equivalence relation T.Equal.
  2. Initially, x = y # NIL and st(x) = st(y) = s.
  3. Then the GC creates a copy s' of s.
  4. Then the GC updates x so that st(x) = s'.
  5. But then y still has the old value: st(y) = s.

At step 5, we have x # y, st(x) # st(y), and T.Equal(x^, y^).  If x is stored in a container for REFANY, then a membership check for x using y will fail, because it can only be based on Refany.Equal.  (If T.Equal is used then we won’t have this problem.)

> REFANY behaves the way the Green Book says it does.

You mean Systems Programming with Modula-3?

— JC Chu

-----Original Message-----
From: mika at async.caltech.edu [mailto:mika at async.caltech.edu] 
Sent: Sunday, March 2, 2014 21:03
To: JC Chu; rodney_bates at lcwb.coop
Cc: m3devel at elegosoft.com
Subject: Re: [M3devel] REFANY-keyed tables?


I just want to make an observation...

REFANY behaves the way the Green Book says it does.  There's not a word in there about concurrent garbage collectors or bit-pattern representations of REFANY.

If a, b : REFANY and a = b then a and b point to the same object.

You can't apply ^ to REFANY.  The only thing you can do to a value beyond = is narrow it to another type.  That's why there's no Hash for REFANY.
(Not because the garbage collector is implemented one way or another.)

Of course you can put REFANY in a list.  You can make as many copies in as many places as you want and = will continue working.

The rest is implementation... 

I'm not saying there isn't a lot of implementation, or that the implementation doesn't have to get clever about some things, but you really don't need to think about the implementation to know what you can and can't do with REFANY.  It's all in the Green Book.

I definitely would not suggest messing with the garbage collector because you want to get something working with REFANY in a pure Modula-3 program.
It defeats the purpose of REFANY.

If you MUST hash a whole bunch of objects that have being REFANY as their only thing in common I'd suggest using TYPECODE and registering hash procedures for each type you're interested in.  This is a simple enough thing that Modula-3's runtime "introspection" facilities more than suffice.  (Those facilities are more limited than Java's, for mostly good reasons.)

     Mika



More information about the M3devel mailing list