[racket] FW: weakly held symbols?
Thanks.
I dont know why Racket wont release quoted literals after disappearing, but
your answer is clear.
Jos
_____
From: Carl Eastlund [mailto:carl.eastlund at gmail.com]
Sent: martes, 28 de enero de 2014 18:13
To: Jos Koot
Cc: Racket Users
Subject: RE: [racket] FW: weakly held symbols?
Racket will generally not release keys that are quoted literals in your
program. Try building your keys using symbol->string.
On Jan 28, 2014 8:16 AM, "Jos Koot" <jos.koot at gmail.com> wrote:
Things work now as I expect for weak boxes, but I am still confused about
weak hash tables. I do the following:
#lang racket
(define h (make-weak-hash))
(define keys
(for/list ((key (in-list '(a b c d e f))))
(make-weak-box key) ; <--- 1
; key ; <--- 2
))
(define (enter key value)
(will-register will-executor value will-proc)
(set! enter-counter (add1 enter-counter))
(hash-set! h key value))
(define-syntax-rule (while condition expr ...)
(let loop () (when condition expr ... (loop))))
(define will-executor (make-will-executor))
(define (will-proc v) (set! release-counter (add1 release-counter)) #t)
(define enter-counter 0)
(define release-counter 0)
(define range (in-range 6))
(for ((key (in-list keys)) (value range)) (enter key (list value)))
(list enter-counter release-counter) ; -> (6 0) ok
h ; -> hash with 6 entries, ok
(set! keys #f) ; discard all keys
(collect-garbage) (collect-garbage)(collect-garbage) (collect-garbage)
(while (will-try-execute will-executor))
(list enter-counter release-counter) ; -> (6 6) ok
h ; -> empty hash, ok
So far ok. However, when commenting out line <--- 1 and uncommenting line
<--- 2, I would expect the same results, but I find:
(6 0) ; ok
hash with 6 entries ; ok
(6 0) ; a surptrise for me
hash with 6 entries ; a surprise for me
This is the cause of my confusion. Surely I am misinterpreting the docs.
Help much appreciated.
Thanks again, Jos
_____
From: Carl Eastlund [mailto:carl.eastlund at gmail.com]
Sent: martes, 28 de enero de 2014 1:28
To: Jos Koot
Cc: Racket Users
Subject: Re: [racket] FW: weakly held symbols?
This isn't a typo. The docs are talking about the properties of the symbol
tables for interned and unreadable symbols. There is no symbol table for
uninterned symbols, so it wouldn't mean anything to talk about it.
Here's what this means for an interned symbol: you can create one, and while
a reference to it exists, it stays in the symbol table. Any time you intern
the same string, you'll get back that symbol. However, if all references to
that symbol vanish, the symbol table is free to release that symbol. If
anyone interns the same string again later, a new symbol will be created.
For nearly all purposes, this is completely transparent, because you
couldn't possibly have a copy of the old symbol to compare. There's almost
no way to tell that the symbol you got before and the one you got after were
different. The only way you'd ever know would be either by tracking memory
use statistics, or by comparing the results of something like eq-hash-code,
neither of which should be surprising to find out behaves impurely.
Carl Eastlund
On Mon, Jan 27, 2014 at 5:53 PM, Jos Koot <jos.koot at gmail.com> wrote:
It appears that my previous email was not sent completely. Sorry for that.
Here is the complete question.
Hi to all,
Section "3.6 symbols" of the Racket reference manual states:
Interned and unreadable symbols are only weakly held ... but a symbol maay
disappear when ... used as the key in a weak hash table ...".
I would understand:
UNINTERNED and unreadable symbols are only weakly held ... but a symbol may
disappear when ... used as the key in a weak hash table ...".
May be just a typo, but as I am not sure I understand the docs well, I post
my question here instead of posting a bug report.
Greetings, Jos
____________________
Racket Users list:
http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140128/38f855fd/attachment-0001.html>