Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!accuvax.nwu.edu!anaxagoras!krulwich From: krulwich@ils.nwu.edu (Bruce Krulwich) Newsgroups: comp.lang.lisp Subject: Re: Weak Reference in Common Lisp Message-ID: <1436@anaxagoras.ils.nwu.edu> Date: 21 Aug 90 14:10:28 GMT References: <81084@aerospace.AERO.ORG> <41670@think.Think.COM> Sender: news@anaxagoras.ils.nwu.edu Reply-To: krulwich@ils.nwu.edu (Bruce Krulwich) Distribution: usa Organization: Institute for the Learning Sciences, Northwestern University, Evanston, IL 60201 Lines: 29 In-reply-to: barmar@think.com (Barry Margolin) Regarding weak reference: In article <41670@think.Think.COM>, barmar@think (Barry Margolin) writes: >I think they're only feasible in cells that are allowed to reference >nothing. Hash table entries meet this requirement because entries may be >removed; symbol value cells and CLOS slots can be "unbound", so weak >references are possible there. But it wouldn't make sense to have a weak >reference from a cons cell -- what does CAR return if the object had been >GCed (I suppose you could wimp out and say that cells that aren't allowed >to be unbound must be set to NIL)? This problem becomes easier to manage if dereferencing a weak pointer had to be done explicitly, similar to T's OBJECT-HASH and OBJECT-UNHASH. Abstracting away from T's version for a minute, you could have: (MAKE-WP ) -- return a weak pointer to (WP-DEREF ) -- return the value pointed to (weakly) by Then the question would not be "what should be done to when its is GC'ed," as barmar seems to say above, but rather "what should WP-DEREF return when 's has been GC'ed." One answer to this question is to model WP-DEREF after GETHASH, and in the case where 's has been GC'ed have it return NIL or a user-specified DEFAULT. Bruce Krulwich krulwich@ils.nwu.edu