[racket] Unexpected procedure identity

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Wed Sep 15 17:27:20 EDT 2010

Contracts are implemented by creating wrapper functions and
define/contract does this by changing how the variable reference
"unfun" works. It actually creates the wrapper function at the point
of the variable reference and so is creating two in this case.

I expect that at some point define/contract may change in the future
to create fewer wrappers; as you can probably guess in this case the
wrappers are identical so we only need one. Probably this exact case
won't change but others may.

In general, when contracts are involved, you cannot rely on eq?-based
identity for procedures. If you want some kind of identity on
procedures, I recommend you use applicable structs.

Robby

On Wed, Sep 15, 2010 at 3:10 PM, Markku Rontu <markku.rontu at iki.fi> wrote:
> Hi everybody,
>
> I don't understand what the difference is with define and define/contract in
> the following cases. Can somebody explain what happens here? Especially why
> does unfun not eq? itself?!?
>
> #lang racket
>
> (define (fun) 'fun)
> (define/contract (unfun) (-> symbol?) 'unfun)
> (define fun? (contract (-> symbol?) fun 'fun '!fun))
>
>> (eq? fun fun)
> #t
>> (eq? unfun unfun)
> #f
>> (eq? fun? fun?)
> #t
>
> Thanks,
> -Markku
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>


Posted on the users mailing list.