Maybe you could make the impersonator (it would be a chaperone, really in what I'm suggesting) signal an error if it gets one of the private keys and then hand out only the hashes with the impersonator around it, keeping the "raw" one around for code that is allowed to access the private keys?
Robby On Fri, Jun 30, 2017 at 11:55 AM, Matthew Butterick <m...@mbtype.com> wrote: > I'd like to make a hash impersonator that has "private" keys that can be > reached by `hash-ref`, but which are not reported by `hash-keys` and other > operations that iterate over all keys. > > The docs for `impersonate-hash` [1] say that you can "use `key-proc` to > filter keys extracted from the table". OK, sounds promising. But later, it > says `key-proc` "must produce a replacement for the key". So apparently it's > more of a map-like operation than a filter-like operation. > > For instance, this key-proc function intends to omit any key but 'foo. But > AFAICT there is no value you can return that signals "please pretend this > key does not exist." > > #lang racket > (define ih (impersonate-hash (make-hash) > (λ (h k) (values k (λ (h k v) v))) > (λ (h k v) (values k v)) > (λ (h k) k) > ;; key-proc below: can I omit keys? I think not > (λ (h k) (if (eq? k 'foo) > k > #f)))) > (hash-set! ih 'foo 42) > (hash-set! ih 'bar 21) > (hash-set! ih 'zam 7) > (hash-keys ih) ; '(#f #f foo), want just '(foo) > > > > [1] > http://docs.racket-lang.org/reference/chaperones.html?q=impersonate-hash#%28def._%28%28quote._~23~25kernel%29._impersonate-hash%29%29 > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.