From: Dave Bakhash
Subject: weak hashtables in LW 4.2
Date: 
Message-ID: <c29bsap5mv8.fsf@no-knife.mit.edu>
Hi,

I want to create a value-weak hashtable in LW 4.2.  I've tried
everything possible to witness see the weak property in action.  Here's
a snipped of my listener:

-------------------------------

CL-USER 71 > (setq ht (make-hash-table))
#<EQL Hash Table{0} 20654F4C>

CL-USER 72 > (setf (gethash 2 ht) "two")
"two"

CL-USER 73 > (gethash 2 ht)
"two"
T

CL-USER 74 > (set-hash-table-weak ht :value)
:VALUE

CL-USER 75 > ()
NIL

CL-USER 76 > ()
NIL

CL-USER 77 > ()
NIL

CL-USER 78 > ()
NIL

CL-USER 79 > ()
NIL

CL-USER 80 > ()
NIL

CL-USER 81 > (normal-gc)
T

CL-USER 82 > (mark-and-sweep 3)
21203816
16038976

CL-USER 83 > (mark-and-sweep 2)
60394
53984

CL-USER 84 > (gethash 2 ht)
"two"
T

-------------------------------

I was hoping _not_ to see the value come back from the call to
gethash.  I'm trying to figure out if the weak hashtable propery works
as I was expecting it to.  

In addition to the above code, I tried other situations, with lots of
intensive crunching between prompts 80 and 81 above, hoping that somehow
Lisp would gc that hashtable entry.  It still didn't work.

Any help is greatly appreciated.

dave

From: Joe Marshall
Subject: Re: weak hashtables in LW 4.2
Date: 
Message-ID: <tWzL8.14874$fT5.3686845@typhoon.ne.ipsvc.net>
I've had no problem with weak hash tables in
lw 4.2, but from the example below, you insert the
key and value pair *before* you make the table weak,
and perhaps weakness is not retroactive.

"Dave Bakhash" <·····@alum.mit.edu> wrote in message ····················@no-knife.mit.edu...
> Hi,
>
> I want to create a value-weak hashtable in LW 4.2.  I've tried
> everything possible to witness see the weak property in action.  Here's
> a snipped of my listener:
>
> -------------------------------
>
> CL-USER 71 > (setq ht (make-hash-table))
> #<EQL Hash Table{0} 20654F4C>
>
> CL-USER 72 > (setf (gethash 2 ht) "two")
> "two"
>
> CL-USER 73 > (gethash 2 ht)
> "two"
> T
>
> CL-USER 74 > (set-hash-table-weak ht :value)
> :VALUE
>
> CL-USER 75 > ()
> NIL
>
> CL-USER 76 > ()
> NIL
>
> CL-USER 77 > ()
> NIL
>
> CL-USER 78 > ()
> NIL
>
> CL-USER 79 > ()
> NIL
>
> CL-USER 80 > ()
> NIL
>
> CL-USER 81 > (normal-gc)
> T
>
> CL-USER 82 > (mark-and-sweep 3)
> 21203816
> 16038976
>
> CL-USER 83 > (mark-and-sweep 2)
> 60394
> 53984
>
> CL-USER 84 > (gethash 2 ht)
> "two"
> T
>
> -------------------------------
>
> I was hoping _not_ to see the value come back from the call to
> gethash.  I'm trying to figure out if the weak hashtable propery works
> as I was expecting it to.
>
> In addition to the above code, I tried other situations, with lots of
> intensive crunching between prompts 80 and 81 above, hoping that somehow
> Lisp would gc that hashtable entry.  It still didn't work.
>
> Any help is greatly appreciated.
>
> dave
From: Barry Margolin
Subject: Re: weak hashtables in LW 4.2
Date: 
Message-ID: <CzKL8.3$qx5.265@paloalto-snr1.gtei.net>
In article <·······················@typhoon.ne.ipsvc.net>,
Joe Marshall <·············@attbi.com> wrote:
>I've had no problem with weak hash tables in
>lw 4.2, but from the example below, you insert the
>key and value pair *before* you make the table weak,
>and perhaps weakness is not retroactive.

Probably not.  Typical implementations of weak tables work by flagging the
constituent object pointers with a "weak" tag.  The weakness property of
the table indicates whether such pointers should be used when inserting
objects into the table.  Any objects inserted before the property was
changed will have been created with the other type of pointer.

The converse of this is that changing a table from weak to normal will not
protect the entries that had previously be inserted.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Clive Tong
Subject: Re: weak hashtables in LW 4.2
Date: 
Message-ID: <uptz3fq2u.fsf@scientia.com>
Barry Margolin <······@genuity.net> writes:

> In article <·······················@typhoon.ne.ipsvc.net>,
> Joe Marshall <·············@attbi.com> wrote:
> >I've had no problem with weak hash tables in
> >lw 4.2, but from the example below, you insert the
> >key and value pair *before* you make the table weak,
> >and perhaps weakness is not retroactive.
> 
> Probably not.  

AFAIK in LispWorks the call to set-hash-table weak causes all of the
items to become weak, and conversely setting the table strong causes
all of the items to lose their weakness. 
From: Dave Bakhash
Subject: Re: weak hashtables in LW 4.2
Date: 
Message-ID: <c29elfjtcyx.fsf@no-knife.mit.edu>
"Joe Marshall" <·············@attbi.com> writes:

> I've had no problem with weak hash tables in lw 4.2, but from the
> example below, you insert the key and value pair *before* you make the
> table weak, and perhaps weakness is not retroactive.

my guess would be that if the question of _when_ you set the hashtable
to be weak or not was in issue, it would (or at least should) be in the
documentation.

Anyway, someone sent me a snippet of code demonstrating how I might get
what I want, showing that wrapping all this in a function and then
compiling it would work.

thanks,
dave
From: Clive Tong
Subject: Re: weak hashtables in LW 4.2
Date: 
Message-ID: <usn3zfqq8.fsf@scientia.com>
Dave Bakhash <·····@alum.mit.edu> writes:

> Hi,
> 
> I want to create a value-weak hashtable in LW 4.2.  I've tried
> everything possible to witness see the weak property in action.  Here's
> a snipped of my listener:
> 
> -------------------------------
> 
> CL-USER 71 > (setq ht (make-hash-table))
> #<EQL Hash Table{0} 20654F4C>
> 
> CL-USER 72 > (setf (gethash 2 ht) "two")
> "two"
> 
> CL-USER 73 > (gethash 2 ht)
> "two"
> T
> 
> CL-USER 74 > (set-hash-table-weak ht :value)
> :VALUE
> 
> CL-USER 75 > ()
> NIL
> 
> CL-USER 76 > ()
> NIL
> 
> CL-USER 77 > ()
> NIL
> 
> CL-USER 78 > ()
> NIL
> 
> CL-USER 79 > ()
> NIL
> 
> CL-USER 80 > ()
> NIL
> 
> CL-USER 81 > (normal-gc)
> T
> 
> CL-USER 82 > (mark-and-sweep 3)
> 21203816
> 16038976
> 
> CL-USER 83 > (mark-and-sweep 2)
> 60394
> 53984
> 
> CL-USER 84 > (gethash 2 ht)
> "two"
> T
> 
> -------------------------------
> 
> I was hoping _not_ to see the value come back from the call to
> gethash.  I'm trying to figure out if the weak hashtable propery works
> as I was expecting it to.  

The string is in the history list for the buffer

  sys::*top-loop-history-list* 

If you set the history items in the :list member of this structure to
nil, then the value disappears as expected (in the LW4.1 in which I
tried this).
From: Dave Bakhash
Subject: Re: weak hashtables in LW 4.2
Date: 
Message-ID: <c29vg8ug5om.fsf@no-knife.mit.edu>
Clive Tong <··········@scientia.com> writes:

> If you set the history items in the :list member of this structure to
> nil, then the value disappears as expected (in the LW4.1 in which I
> tried this).

This is great news.  I didn't know that LW kept such a lost history...I
only thought there was *, **, and *** and that was it.

thanks,
dave