•
Exercise:
Creating Contracts From Examples
Exercise:
Creating Contracts From Examples
Exercise: Creating Contracts From Examples
Directions:
For each of the following collections of
Example
s, write the contract for the function above the examples.
;
:
->
(EXAMPLE (third-root 16) (expt 16 1/3) (EXAMPLE (third-root 125) (expt 125 1/3) (EXAMPLE (third-root 625) (expt 625 1/3)
;
:
->
(EXAMPLE (sentence-length "hello" 5) (+ (string-length "hello") 5)) (EXAMPLE (sentence-length "please" 6) (+ (string-length "please") 6)) (EXAMPLE (sentence-length "goodbye" 10) (+ (string-length "please") 10))
;
:
->
(EXAMPLE (upside-down (triangle 50 "solid" "yellow")) (rotate 180 (triangle 50 "solid" "yellow"))) (EXAMPLE (upside-down (star 150 "outline" "blue")) (rotate 180 (star 150 "outline" "blue")))
;
:
->
(EXAMPLE (product-squared 5 6) (sqr (* 5 6)) (EXAMPLE (product-squared 10 17) (sqr (* 10 17))) (EXAMPLE (product-squared 2 5) (sqr (* 2 5)))
;
:
->
(EXAMPLE (half-image "www.images.com/cat_image") (scale .5 (bitmap/url "www.images.com/cat_image"))) (EXAMPLE (half-image "www.images.com/dog_image") (scale .5 (bitmap/url "www.images.com/dog_image")))
;
:
->
(EXAMPLE (triple 4) (* 4 3)) (EXAMPLE (triple 10) (* 10 3)) (EXAMPLE (triple 3) (* 3 3))
Bootstrap by Emmanuel Schanzer, Emma Youndtsmith, Kathi Fisler, Shriram Krishnamurthi, Joe Politz and Ben Lerner is licensed under a
Creative Commons 4.0 Unported License
. Based on a work at
www.BootstrapWorld.org
. Permissions beyond the scope of this license may be available by contacting
schanzer@BootstrapWorld.org
.