[plt-dev] symbol->string and mutability

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jun 18 16:34:18 EDT 2009

At Thu, 18 Jun 2009 16:27:02 -0400, Carl Eastlund wrote:
> On Thu, Jun 18, 2009 at 4:03 PM, Matthew Flatt<mflatt at cs.utah.edu> wrote:
> >>
> >> I see.  I have contracts set up to accept only symbols and keywords
> >> whose names are ASCII strings; I was planning to use a weak, eq?-based
> >> hash of their names to shortcut the test.  Apparently, though, I
> >> cannot get eq?-unique names for symbols and strings.  If I hash the
> >> symbols and keywords themselves, I believe the weak table can never
> >> reclaim the space (since interned symbols and keywords are forgeable);
> >
> > No --- symbols and keywords are GCed, so a weak hash table would work.
> >
> > (And weakness in hash tables isn't about whether you could synthesize
> > the key. We have `equal?'-based hash tables with weak keys, after all.)
> 
> I see.  I tried to demonstrate this one way or another to myself with
> a weak box containing a symbol and a call to collect-garbage, and the
> box never "emptied".  Perhaps that experiment was not conclusive;
> maybe collect-garbage doesn't guarantee emptying of all weak boxes, or
> I had a reference to the symbol lying around somewhere I didn't know
> about.

I tried this in the MzScheme and DrScheme (module language) REPLs:

 > (define b (make-weak-box 'not-used-elsewhere))
 > (weak-box-value b)
 not-used-elsewhere
 > (collect-garbage)
 > (weak-box-value b)
 #f

Did you try the same thing?



Posted on the dev mailing list.