CPSC 110 Lecture 17: CPSC 110

116 views5 pages
Verified Note
31 Oct 2018
School
Course
Professor

Document Summary

;; region data definition provided. (@htdd region) (define-struct single (label weight color)) (define-struct group (color subs)) ;; single regions have label, weight and color. ;; groups just have a color and a list of sub-regions. ;; weight is a unitless number indicating how much weight. [(group? r) ( (group-color r) (fn-for-lor (group-subs r)))])) (define (fn-for-lor lor) (cond [(empty? lor) ()] [else ( (fn-for-region (first lor)) (fn-for-lor (rest lor)))])) ;; design an abstract fold function for region. (@problem 1) (@signature (string natural color -> x) (color y -> x) (x y -> y) y region -> x) ;; abstract fold for region (check-expect (fold-region make-single make-group cons empty g4) g4) (@template region (listof region) encapsulated) ; step 1 step 2 step 3 (define (fold-region c1 c2 c3 b1 r) (local [(define (fn-for-region r) ; -> x (cond [(single? r) (c1 (single-label r) ; string c1 is (single-weight r) ; natural (string natural color.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers