Subject: weak hash tables implementable through FINALIZE?

From: [email-masked] (Jorg-Cyril Hohle)
Date: Sat, 7 Mar 1998 20:56:02 +0100

Hi,

I think I once read an explanation about how to create weak hash
tables through the use of CLISP's FINALIZE, but now I can't seem to
find out a way to do so.  In the opposite direction however, I can
think how an implementation with weak-pointers can be expanded to
implement FINALIZE.

So is there a way in CLISP?

Thanks for your help,
	Jo"rg Ho"hle.
[email-masked]		http://zeus.gmd.de/~hoehle/amiga-clisp.html

---

From: Bruno Haible <[email-masked]>
Date: Tue, 10 Mar 1998 14:54:55 +0100 (MET)

> So is there a way in CLISP?

It is possible to implement FINALIZE using weak hash table, weak sets,
or weak pointers.

It doesn't seem possible to implement weak hash tables when all you have
is FINALIZE. I think (but would be happy if someone could prove this
formally) that FINALIZE triggers a function which gets called when the
reference count of some object drops to 0, whereas for weak hash tables
you need to trigger a function when the reference count drops to 1.

Bruno

---

From: Don Cohen <[email-masked]>
Date: Tue, 10 Mar 1998 21:28:53 -0800

I think you can implement weak tables with finalize.
Whenever you enter something in a weak table, give it a 
finalization that, if it's still there, will remove it.

How does one implement finalize with weak hash tables?
My impression was that these did not give you the ability to
notice or otherwise do anything when the object was removed.
In either case it seems that it's the GC that's critical here.
It's not when the reference count goes to zero that you want to
do something but when the object becomes gc-able (even if it is
referenced by itself or other garbage).   I suppose the way to
do weak tables is not to mark from them, but after each gc mark
phase, when you can tell whether something is garbage, you have 
to iterate through the weak tables, or in the case of incremental
gc, you need to know which pointers to new stuff have been written
in the weak tables.

Are any of these things in clisp?

---

From: [email-masked] (Jorg-Cyril Hohle)
Date: Tue, 24 Mar 1998 17:44:49 +0100

> finalization that, if it's still there, will remove it.
You must be able to access present data in the table. If it's still in
the table, it will not be finalized.  Thus the GC must treat this
table specially, thus it's no simple (Lisp only) solution that I was
looking for.

 > How does one implement finalize with weak hash tables?
I said "can be expanded" because I think that a Lisp system which
contains a mechanism to support weak hash tables wouldn't require many
modifications to be able to handle finalize: their support is similar,
both must be treated specially by the GC.  The converse seems true as
well.

 > do weak tables is not to mark from them, but after each gc mark
Correct.

 > Are any of these things in clisp?
FINALIZE only, see impnotes.txt.

	Jo"rg Ho"hle.