i am working through the htdp book online and i came across and excerise which asks me to
Then create an expression that converts the value of in to a non-negative number. For a String, it determines how long the String is; for an Image, it uses the area; for a Number, it uses the absolut value; for #true it uses 10 and for #false 20. Hint Check out cond from the Prologue: How to Program (again).
the last part is the issue it wants to write a predicate which returns 10 or 20 depending on the value of inn. this is my code so far
(define inn "abc")
(cond
[(string? inn ) (string-length inn)]
[(image? inn) ( + (image-width) (image-height))]
[(number? inn) (abs inn)]
[(boolean? inn #true) (boolean? inn #false)] 10 20)
so if put false as the input of the def inn it should return 20.
I fixed small syntactic mistakes in the last line:
(require 2htdp/image)
(define inn "abc")
(cond
[(string? inn ) (string-length inn)]
[(image? inn) ( + image-width image-height)]
[(number? inn) (abs inn)]
[(boolean? inn) (if (boolean=? inn #false) 10 20)])
I restored another mistake so you aren’t “home” yet.
Recommendation: Open Help Desk. Search boolean?. Follow the link to the BSL version. Take a close look. ~~ While you’re there, explore some more of the functions that you might need | like | use in the future.