[racket] Unexpected procedure identity

From: Markku Rontu (markku.rontu at iki.fi)
Date: Thu Sep 16 02:40:44 EDT 2010

Thanks for the info.

On Thu, Sep 16, 2010 at 12:27 AM, Robby Findler <robby at eecs.northwestern.edu
> wrote:

> 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.
>

My next question might have been how have you implemented contracts, i.e.
how do you attach contracts to procedures? In this case you definitely need
to wrap the procedure so that the contract gets called in the appropriate
places but I'm surprised it's done at the reference site and not in the
definition.


> 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.
>

What I'm trying to do is to attach certain metadata to procedures. So I need
a way to map from procedures to their metadata. Any ideas on how to
implement this? Am I really forced to wrap everything behind my own wrapper
that provides me a workable identity for each procedure?

So there is no reliable way to refer to procedures and attach the metadata
but that I need to always custom-define and wrap them? This would mean there
is no reliable way to attach metadata to third party procedures that may or
may not be defined with define/contract? Or I have to make require to wrap
everything required too somehow? Then there is of course the question of
macros and attaching metadata to them...

In general, it would be nice to have a standard way of attaching metadata to
any value. Or is this a silly idea?

-Markku


> 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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100916/73594c2d/attachment.html>

Posted on the users mailing list.