;; a circle is a (make-circle posn number) (define-struct circle (center radius)) ;; A list-of-circles is ;; - empty ;; - (cons circle list-of-circles) ;; EXAMPLES OF DATA (define locirc1 empty) (define locirc2 (cons (make-circle (make-posn 3 4) 15) (cons (make-circle (make-posn -2 5) 5) (cons (make-circle (make-posn 50 20) 100) empty)))) ;; TEMPLATES ;(define (circle-func acirc) ; (circle-center acirc) ... ; (circle-radius acirc) ...) ; ;(define (loc-func aloc) ; (cond [(empty? aloc) ...] ; [(cons? aloc) ; ... (circle-func (first aloc)) ; ... (loc-func (rest aloc)) ...])) ;; Write a program large-circles, which consumes a list of circles and returns ;; a list of the circles with radius larger than 10 ;; EXAMPLES OF PROGRAM ;(large-circles locirc1) = empty ; ;(large-circles locirc2) = (cons (make-circle (make-posn 3 4) 15) ; (cons (make-circle (make-posn 50 20) 100) ; empty)) ;; WRITING THE ACTUAL PROGRAM ;; Start with the template for list-of-circles, and add a contract and purpose, ;; and customize the name of loc-func ;; large-circles : list-of-circles -> list-of-circles ;; return a list of those circles with radius larger than 10 (define (large-circles aloc) (cond [(empty? aloc) ...] [(cons? aloc) ... (circle-func (first aloc)) ... (large-circles (rest aloc)) ...])) ;; Use the examples to fill in the empty case, and think about the cons case. ;; Reading the purpose tells you that (large-circles (rest aloc)) returns ;; the list of large circles in the rest of the list. So you just need to ;; decide whether the first circle belongs on that list. Looking at the template, ;; you pass (first aloc) to circle-func -- this suggests that circle-func ;; should determine whether a circle is large. ;; large-circles : list-of-circles -> list-of-circles ;; return a list of those circles with radius larger than 10 (define (large-circles aloc) (cond [(empty? aloc) empty] [(cons? aloc) ... (large? (first aloc)) ... (large-circles (rest aloc)) ...])) ;; Now, you just need a cond to put the first circle on the list depending ;; on whether or not it is large: ;; large-circles : list-of-circles -> list-of-circles ;; return a list of those circles with radius larger than 10 (define (large-circles aloc) (cond [(empty? aloc) empty] [(cons? aloc) (cond [(large? (first aloc)) (cons (first aloc) (large-circles (rest aloc)))] [else (large-circles (rest aloc))])])) ;; That finishes large-circles. To finish the program, customize the circle-func ;; template to implement large? ;; large? : circle -> boolean ;; determine whether circle has radius at least 10 (define (large? acirc) (> (circle-radius acirc) 10)) ;; Finally, test your program on the example data. ;; -------------------------------------------------------------------------------- ;; WHAT A COMPLETE SOLUTION WOULD LOOK LIKE ;; Since this document has mixed demonstration with code, here's what we'd expect ;; as a full solution to this problem written up according to the laws of homework ;; DATA DEFINITIONS ;; a circle is a (make-circle posn number) (define-struct circle (center radius)) ;; A list-of-circles is ;; - empty ;; - (cons circle list-of-circles) ;; EXAMPLES OF DATA (define locirc1 empty) (define locirc2 (cons (make-circle (make-posn 3 4) 15) (cons (make-circle (make-posn -2 5) 5) (cons (make-circle (make-posn 50 20) 100) empty)))) ;; TEMPLATES (if we asked for them) (define (circle-func acirc) (circle-center acirc) ... (circle-radius acirc) ...) (define (loc-func aloc) (cond [(empty? aloc) ...] [(cons? aloc) ... (circle-func (first aloc)) ... (loc-func (rest aloc)) ...])) ;; EXAMPLES OF PROGRAM ;(large-circles locirc1) = empty ; ;(large-circles locirc2) = (cons (make-circle (make-posn 3 4) 15) ; (cons (make-circle (make-posn 50 20) 100) ; empty)) ;; THE ACTUAL PROGRAM ;; large-circles : list-of-circles -> list-of-circles ;; return a list of those circles with radius larger than 10 (define (large-circles aloc) (cond [(empty? aloc) empty] [(cons? aloc) (cond [(large? (first aloc)) (cons (first aloc) (large-circles (rest aloc)))] [else (large-circles (rest aloc))])])) ;; large? : circle -> boolean ;; determine whether circle has radius at least 10 (define (large? acirc) (> (circle-radius acirc) 10)) ;; TESTS (large? (make-circle (make-posn 3 4) 15)) (large? (make-circle (make-posn -2 5) 5)) (large-circles locirc1) (large-circles locirc2)