<br><div class="gmail_quote">On Sat, Mar 28, 2009 at 9:15 AM, Sam TH <span dir="ltr"><<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
</div>This does not help at all. Imagine that the 'not-found-value' is<br>
called QQQ. Then we have two choices:<br>
<br>
- QQQ is a value in our language. Then it can be stored in the hash,<br>
and we can't tell if we need to throw an exception. This is the<br>
current situation.<br></blockquote><div><br>I believe the internal hash-has-key? should be exposed, since hash-ref obviously has to make such a test in order to decide whether to return the default value. <br><br>But it's possible to implement the QQQ value if the client has to implement the hash-has-key? function, by utilizing make-struct-type, since each call to make-struct-type will create a unique struct type that cannot equal any other structs. And as long as we do not expose its make function, the client can never make and store such a value in the hash.<br>
<br><span style="font-family: courier new,monospace;">(define hash-has-key?</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (let-values (((s make isa? ref set!)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (make-struct-type 'QQQ #f 0 0 )))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (lambda (hash key)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (not (isa? (hash-ref hash key (make)))))))</span><br style="font-family: courier new,monospace;"><br>Cheers,<br>yc<br><br></div></div>