When should you create a structure (use define-struct)?
Does a structure define data or a form of computation?
What does DrScheme define as a result of a define-struct?
Why do we write data definitions? (Put another way, what would go wrong if we did not write them?)
Is the following code a complete data definition? If not, what is it missing (and why does that matter)?
(define-struct address (housenum street city state zip))
Critique the following code and data definition: do you recommend any changes and if so, why?
; An elephant is a (make-elephant weight number) (define-struct elephant (number num-tusks)) ;; too-heavy? : elephant -> boolean ;; consume elephant and determine if it weighs more than 1000 pounds (define (too-heavy? an-ele) (> (elephant-number an-ele) 1000))
Continuing with the code in the previous problem, what is
Write test cases for
too-heavy? from the code above.
Assume we want to write programs over shapes, where possible shapes are circles (with a radius) and rectangles (with a width and height). Give a data definition and template for shapes.
Write a program
area that consumes a shape and
produces its area (a number).