ANN: Dogelog Runtime, Prolog to the Moon (2021)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Sep 17 23:49:16 EDT 2021


On 17/09/21 7:56 am, Mostowski Collapse wrote:
> The trail in Dogelog
> Runtime is a single linked list:
> 
>      -->[ A ]-->[ B ]-->[ C ]-->
> 
> Now if B becomes unused, you need to rewire
> the trail, it should then look like:
> 
>      -->[ A ]---------->[ C ]-->

Python has a way of creating weak references (see the weakref
module). You could set the trail up like this:

-->[*]-->[*]-->[*]-->
     |     |     |
     v     v     v
    [w]   [w]   [w]
     :     :     :
     v     v     v
    [A]   [B]   [C]

where [w] is a weak reference object. Then you could periodically
scan the trail looking for dead weakref objects and remove the
corresponding [*] node from the list.

You can also attach callbacks to weakref objects that are triggered
when the referenced object dies. You might be able to make use of
that to remove items from the trail instead of the periodic scanning.

-- 
Greg


More information about the Python-list mailing list