<div>Hi Robby - </div><div><br></div><div>What I am trying to do is to look up a key/value pair where the key happens to be the procedure.  The struct idea will work only if I can serialize/hash the procedure into a unique key, which means I will still have to rely on a procedure matching itself (otherwise it&#39;s too much work for the client). </div>
<div><br></div><div>The scenario really boils down to - why does a contracted procedure not eq itself?  </div><div><br></div><div>The same script above shows that a contracted procedure returns #f with eq?, but a plain procedure returns #t in REPL (both returns #t in module). </div>
<div><br></div><div><div>&gt; (eq? test? test?) ;; test? is contracted. </div><div>#f</div><div>&gt; (eq? test2? test2?) ;; test2? is not contracted </div><div>#t</div></div><div><br></div><div>Looking at the <a href="http://docs.racket-lang.org/reference/booleans.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29">definition of eq?</a> shows that eq? is for determining whether two objects are the same.  And since both test? and test2? are exposed via a module, i.e. they are &quot;fixed&quot; once exposed outside of module, whether contracted or not - I would have expected eq? would return #t for both cases in REPL. </div>
<div><br></div><div>Am I misunderstand what eq? is all about?  Thanks. </div><div><br></div><div>yc</div><div><br></div><div class="gmail_quote">On Wed, Jul 21, 2010 at 5:40 PM, Robby Findler <span dir="ltr">&lt;<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You seem to be relying on identity of procedures (which is a bad<br>
idea). Contracts on functions are implemented with wrappers which<br>
breaks that by making fewer things equal but compiler optimizations<br>
can take things the other direction making more things equal than you<br>
might expect.<br>
<br>
Overall I think you should just avoid relying on the identity of<br>
procedures. One way to do that (without knowing more about your code)<br>
would be to use struct procedures and put an extra field on the struct<br>
that gives you the key for a comparison.<br>
<br>
Hth,<br>
<font color="#888888">Robby<br>
</font><div><div></div><div><br>
On Wednesday, July 21, 2010, YC &lt;<a href="mailto:yinso.chen@gmail.com" target="_blank">yinso.chen@gmail.com</a>&gt; wrote:<br>
&gt; Hi all -<br>
&gt;<br>
&gt; I am running into an interesting issue where an alist of procedures in REPL, the ones without a contract works with assoc, but the ones with contract do not work with assoc.<br>
&gt;<br>
&gt; What I have is an alist where the keys are procedures.  Some of these procedures have contracts attached to them, and some do not.  Then I tried to use assoc to match the procedures.  If the code are run within the module itself - both types match, but within REPL only the ones without contract matches.<br>


&gt;<br>
&gt; Here&#39;s an simplified example, where foo.ss defines the procedures, and the test.ss uses foo.ss to construct the alist.<br>
&gt;<br>
&gt; ;; foo.ss<br>
&gt; #lang scheme<br>
&gt; (define (test? v) #t) ;; provided with contract<br>
&gt;<br>
&gt; (define (test2? v) #t) ;; provided without contract<br>
&gt;<br>
&gt; (provide/contract<br>
&gt;  (test? (-&gt; any/c boolean?))<br>
&gt;  )<br>
&gt;<br>
&gt; (provide test2?)<br>
&gt;<br>
&gt; ;; test.ss<br>
&gt; #lang scheme<br>
&gt; (require &quot;foo.ss&quot;)<br>
&gt;<br>
&gt; (define table `((,test2? . 1) (,test? . 2)))<br>
&gt;<br>
&gt; (assoc test? table) ;; works in module setting but not in REPL<br>
&gt;<br>
&gt; (assoc test2? table) ;; works in module setting AND in REPL<br>
&gt;<br>
&gt; Both the assoc test above returns the correct result.  But if I try to copy and run (assoc test? table) in REPL again, it will not match, whereas (assoc test2? table) continues to match.<br>
&gt;<br>
&gt; Is there any particular reason for the divergence of the behaviors?  I verified the behavior in both v4.2.5 and v5.0.  Thanks.<br>
&gt;<br>
&gt; yc<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Cheers,<br>yc<br><br>Taming the software dragon - <a href="http://dragonmaestro.com" target="_blank">http://dragonmaestro.com</a><br><br>