weak hashtables in LW 4.2 
Author Message
 weak hashtables in LW 4.2

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



Mon, 22 Nov 2004 07:25:47 GMT  
 weak hashtables in LW 4.2
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.
Quote:

> 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



Mon, 22 Nov 2004 10:38:17 GMT  
 weak hashtables in LW 4.2

Quote:

>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.

--

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.



Mon, 22 Nov 2004 22:44:50 GMT  
 weak hashtables in LW 4.2

Quote:

> 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).



Tue, 23 Nov 2004 16:16:47 GMT  
 weak hashtables in LW 4.2

Quote:



> >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.


Tue, 23 Nov 2004 16:30:49 GMT  
 weak hashtables in LW 4.2

Quote:

> 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



Tue, 23 Nov 2004 21:50:14 GMT  
 weak hashtables in LW 4.2

Quote:

> 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



Wed, 24 Nov 2004 05:06:01 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. LW 4.2 on Linux and ODBC/InterBase (FireBird)

2. String HashTables

3. another problem with hashtables

4. Hashtables in Lisp

5. string or int hashtables

6. Returning result sets from db2 stored procs to vast 4.2

7. VC++ 4.2 lib problems

8. G-Calc 4.2 now available

9. UltraTree Professional 4.2

10. R&R, Novell 4.2

11. Novell 4.2, NDS, Client 32 and Clipper

 

 
Powered by phpBB® Forum Software