On Thu, Sep 16, 2010 at 1:40 AM, Markku Rontu <markku.rontu at iki.fi> wrote:
> 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.
Since blame might be assigned to the use site, the wrapper has to come there.
>>>> 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?
For procedures at least, you might look at structs-as-procedures. You
can make a struct that contains a function in such a way that the
struct actually acts as a function and uses the contained function
when it is called, etc.
http://docs.racket-lang.org/reference/procedures.html?q=prop:&q=struct#(def._((lib._racket/private/base..rkt)._prop~3aprocedure))
Robby