[racket] Understanding contracts

From: Spencer florence (spencerflorence at gmail.com)
Date: Thu Oct 2 00:07:31 EDT 2014

Where are you calling `cubic-bezier` from? If its from the REPL, the module itself, or a submodule the function won’t have a contract attached. Only code outside `cubic-bezier`s module will have the version of `cubic-bezier` with a contract attached.

On Wed, Oct 1, 2014 at 9:46 PM, Alexander McLin <alex.mclin at gmail.com>

> Hello,
> I've been working on a sample project to better understand how to use the
> contract system. I created a simple Bezier curve implementation and am
> using (provide (contract-out...) to attach contracts to the provided
> bindings.
> Basically I have a procedure called cubic-bezier that accepts two control
> point structs used to define the curve. It returns another procedure that
> actually generates the curve, it accepts an integer parameter that lies on
> [0, 1] and an optional keyword #:clamp-range. The generator procedure
> returns a number.
> The control point structure is a simple posn type that accepts X and Y
> fields where X must be between 0 and 1, and Y is allowed to be any number.
> Here are the contracts I defined provisionally:
> (provide (contract-out
>           [struct bezier-control-point ((x (and/c number? (between/c 0 1)))
>                                                       (y number?))]
>           [cubic-bezier (-> bezier-control-point?
>                                      bezier-control-point?
>                                     (->* ((and/c number? (between/c 0 1)))
>                                            (#:clamp-range boolean?)
>                                            number?))]))
> For the contract attached to cubic-bezier using ->, my thinking was to use
> ->* to generate the contract for the procedure returned by cubic-bezier but
> it's not working, meaning I'm not getting the any contract violations I'm
> expecting when giving bad inputs to cubic-bezier's value.
> How can I attach a more complex contract to cubic-bezier's value?
> Thank you
> Alexander McLin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141001/a925b0ee/attachment.html>

Posted on the users mailing list.