[plt-scheme] low-level contract constructors

From: Dave Herman (dherman at ccs.neu.edu)
Date: Tue Sep 9 09:32:32 EDT 2008

Great, thanks for the (incredibly) quick response!

Thanks,
Dave

Robby Findler wrote:
> On Tue, Sep 9, 2008 at 8:23 AM, Dave Herman <dherman at ccs.neu.edu> wrote:
>> In parameter.plt I have a struct-as-procedure called a pseudo-parameter with
>> a high-order contract constructor pseudo-parameter/c. I discovered a couple
>> little issues with the scheme/contract library in the process.
>>
>> - The undocumented `proj-get' procedure seems necessary for a higher-order
>> contract constructor, since you need to use the projection of the underlying
>> contract in building the new one.
>>
>> - The `flat-proj' procedure isn't exported from scheme/contract, but it's
>> also needed for a higher-order contract, in case the underlying contract is
>> flat. So I copied its definition from contract-guts.ss and pasted it into my
>> module.
> 
> I have not spent the time to properly document and export the tools to
> build new contract combinators (partly because they have changed a
> bunch and partly because I just haven't gotten to it).
> 
>> Robby, if by chance you have a moment, could you take a look at
>>
>> http://planet.plt-scheme.org/package-source/dherman/parameter.plt/1/3/main.ss
>>
>> and tell me if pseudo-parameter/c looks plausible?
> 
> It seems fine on a quick look.
> 
>> It seems to work for the
>> test cases I've tried, but it's a little confusing so I'm not sure I've got
>> it right. Particularly the call to ((proj-get c) c) looks weird.
> 
> That's fine.
> 
>> Also, I
>> seem to be getting the object-name wrong when wrapping a function contract,
>> e.g.:
>>
>>    (module a scheme
>>      (require (planet dherman/parameter:1:3))
>>      (define p
>>        (let ([f add1])
>>          (make-pseudo-parameter
>>            (lambda () f)
>>            (lambda (g)
>>              (set! f g)))))
>>      (provide/contract [p (pseudo-parameter/c (-> number? number?))]))
>>
>>    > (require 'a)
>>    > (p)
>>    #<procedure:unsaved-editor4117:9:47>
> 
> I don't think you can do much better. You're making a wrapper
> function, so you're going to have that wrapper function's name, not
> the name `add1'. The same thing happens like this:
> 
> #lang scheme/load
> 
> (module m scheme
>   (provide/contract [f (-> (-> number? number?))])
>   (define (f) add1))
> 
> (module n scheme
>   (require 'm)
>   (printf "~s\n" (f)))
> 
> (require 'n)
> 
> Robby



Posted on the users mailing list.