[plt-scheme] Contract changes a parameter-procedure to a procedure. Why?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri Apr 16 13:45:21 EDT 2010

On Fri, Apr 16, 2010 at 1:30 PM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> I had the bright (?) idea of specifying a contract for a parameter. But:
>
> #lang scheme
>
> (define p1
>  (make-parameter #f))
>
> (parameter? p1) ; --> #t
> p1 ; --> #<procedure:parameter-procedure>
>
> (define/contract p2
>  (() (boolean?) . ->* . (or/c boolean? void?))
>  (make-parameter #f))
>
> (parameter? p2) ; --> #f   Why?
> p2 ; --> #<procedure>      Why?
>
> I discovered this when I made a contract for a procedure that requires
> its argument to be a parameter. I can't use parameter? I'd have to
> settle for procedure?.
>
> Is this because the contract is implemented as a wrapper procedure,
> and the parameter? predicate only sees the contract wrapper procedure
> not the parameter-procedure inside?

That's exactly it.  Use parameter/c instead; it constructs a
parameter-friendly wrapper.

--Carl


Posted on the users mailing list.