Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!enews.sgi.com!news.mathworks.com!hunter.premier.net!www.nntp.primenet.com!nntp.primenet.com!howland.erols.net!netcom.com!hbaker
From: hbaker@netcom.com (Henry Baker)
Subject: Re: Cscheme - Weak Pairs
Content-Type: text/plain; charset=ISO-8859-1
Message-ID: <hbaker-0509960951090001@10.0.2.1>
Sender: hbaker@netcom6.netcom.com
Content-Transfer-Encoding: 8bit
Organization: nil
X-Newsreader: Yet Another NewsWatcher 2.2.0
References: <50ml9p$2kn@decius.ultra.net>
Mime-Version: 1.0
Date: Thu, 5 Sep 1996 17:51:09 GMT
Lines: 34

In article <50ml9p$2kn@decius.ultra.net>, DDL <ddl@DBRC.com> wrote:

> The MIT version of Cscheme has this data structure called a "weak
> pair", which if I understand it correctly, is a cons that is
> automatically reclaimed during the next garbage collection.  Thus I
> query the powers that know:
> 
> 1.  Is this the correct definition of a weak pair?
> 
> and:
> 
> 2.  What are they good for?  I mean, what use is a data structure
> whose contents cannot be guaranteed at any time?  Do you use them
> inside protected code segments?  What's the lowdown?

I don't know Cscheme, but here is my understanding of weak pairs:

1.  A 'weak pair' would be a pair whose car & cdr would _not_ be traced
by the GC, but if those nodes were marked at the end of the GC, then the
pair would be preserved.  If, on the other hand, the car and/or cdr nodes
were _not_ marked at the end of the GC, then the car and/or cdr would be
set to 'nil'.

2.  Weak pairs are good for 'backpointers' and other sorts of 'redundant'
connections, where if the object is unreferenced by a 'non-weak' pointer,
then it will get garbage-collected, and any 'weak pointers' to it will be
reset to nil.

Needless to say, you should have a pretty good idea of what you are doing,
since weak pointers add a kind of asynchronous uncertainty to any pointer
dereferencing.

(In some other Lisp implementations, only the _car_ of a pair is weak, while
the _cdr_ is strong.)
