Referenced from lesson Defining Functions

Directions: For each of the following collections of Examples, write the contract for the function above the examples.

  1. ; : ->
    (EXAMPLE (third-root 16) (expt 16 1/3) (EXAMPLE (third-root 125) (expt 125 1/3) (EXAMPLE (third-root 625) (expt 625 1/3)

  2. ; : ->
    (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))

  3. ; : ->
    (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")))

  4. ; : ->
    (EXAMPLE (product-squared 5 6) (sqr (* 5 6)) (EXAMPLE (product-squared 10 17) (sqr (* 10 17))) (EXAMPLE (product-squared 2 5) (sqr (* 2 5)))

  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")))

  6. ; : ->
    (EXAMPLE (triple 4) (* 4 3)) (EXAMPLE (triple 10) (* 10 3)) (EXAMPLE (triple 3) (* 3 3))

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). CCbadge Bootstrap:Algebra by Emmanuel Schanzer, Jen Poole, Ed Campos Jr, Flannery Denny, and Dorai Sitaram 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.