I have the following dumb test code:
#lang racket
(define vars '('g1 'g2 'g3 'g1))
(define addrs '(123 456 789 012))
(define immhs (make-immutable-hasheq empty))
(define immhs* (for/fold ([imhs immhs]) ([var (in-list vars)] [addr (in-list addrs) ]) (hash-set imhs var addr )))
immhs*
(hash-ref immhs* 'g1)
The output is:
'#hasheq(('g1 . 123) ('g2 . 456) ('g3 . 789) ('g1 . 12))
hash-ref: no value found for key: 'g1
Why can’t the hash-ref reference to the 'g1? (it will also fail on 'g2, etc)
Then I uses (hash-keys immhs*), it returns '('g1 'g2 'g3 'g1), where there is 'g1;
and I use further (car (hash-keys immhs*)), it returns ''g1 ; then the question is that why there are two quote ' before?
The problem is exactly the two quotes that you see:
xevaluates to whateverxis bound to,'xevaluates to a symbol, and''xevaluates to a quoted form —'x. Try this:and it will work.