Please send questions to
st10@humboldt.edu .
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-abbr-reader.ss" "lang")((modname boa-struct) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;--------------------------------
; data definition for a boa:
; (from Ian Barland and John Clements, Cal-Poly June 08
; TeachScheme!/ReachJava workshop)
(define-struct boa (color length food))
; a boa is a
; (make-boa color number symbol)
; a boa has:
; a color that is that boa's main color,
; a length from head to tail in meters, and
; a food that is its favorite food
; template for a function expecting a boa parameter a-boa:
;(... (boa-color a-boa) ...
; (boa-length a-boa) ...
; (boa-food a-boa) ...)
; template for a function producing a boa:
; (make-boa ... ... ...)
; example boa!
(define MY-FIRST-BOA (make-boa "tan" 10 "pizza"))
(check-expect (boa-color MY-FIRST-BOA)
"tan")
(check-expect (boa-length MY-FIRST-BOA)
10)
(check-expect (boa-food MY-FIRST-BOA)
"pizza")
; The scenario that has boas wants to be able to tell if a given
; boa is portable or not -- that is, if it can be carried
; in a carrier of a given size;
;----------
; signature: boa-portable?: boa number -> boolean
; purpose: expects a boa and the length of a carrier in meters,
; and produces whether that boa could fit in a carrier of that
; size (assuming that, for maximum comfort, the length of the
; carrier should be at least the length of the boa)
; 3 specific examples/test cases: a true case, a false case,
; and a boundary case
(check-expect (boa-portable? (make-boa "green" 3 "arugula")
4)
true)
(check-expect (boa-portable? (make-boa "green" 3 "arugula")
2)
false)
(check-expect (boa-portable? (make-boa "green" 3 "arugula")
3)
true)
(define (boa-portable? a-boa carrier-length)
(<= (boa-length a-boa) carrier-length)
)
(boa-portable? (make-boa 'green 3 'arugula)
4)