Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using dr racket redesign find-path/list so that it uses an existing list abstraction from figures 95 and 96 instead of explicit structural recursion. Hint Read
Using dr racket redesign find-path/list so that it uses an existing list abstraction from figures 95 and 96 instead of explicit structural recursion. Hint Read the documentation for Rackets ormap. How does it differ from ISL+s ormap function? Would the former be helpful here?
trl+s ]N [N -X] -[List-of X] ; constructs a list by applying f to , 1, , (sub1 n) ; (build-list n f)-(list (f ) (f (-n 1))) (define (build-listnf) ...) ; [X] [XBoolean] [List-of X] - [List-of X] ; produces a list from those items on lx for which p holds (define (filter p ) ) ; [X] [List-of X] [X X - Boolean] -[List-of X] ; produces a version of that is sorted according to cmp (define (sort lx cmp) ...) ; [XY] [X-> Y] [List-of X] -> [List-of Y] ; constructs a list by applying f to each item on ; (map f (list x-1 X-n))(list (f x-1) (f x-n)) (define (map f lx) ...) ; [X] [XBoolean] [List-of X] - Boolean ; determines whether p holds for every item on lx ; (andmap p (list x-1 x-n)) -= (and (p x-1) (p x-n)) (define (andmap p lx) ...) ; [X] [XBoolean] [List-of X] - Boolean ; determines whether p holds for at least one item on lx ; (ormap p (listx-1 x-n)) -(or (p x-1) (p x-n)) (define (ormap p ) ) ; applies f from right to left to each item in lx and b ; (foldr f b (list x-1 x-n))(f x-1 (f x-n b)) (define (foldr f b ) ) (foldr0'(1 2 3 4 5)) (+1 (+2 12)) ; applies f from left to right to each item in lx and b ; (foldl f b (list x-1 x-n))(f x-n (f x-1 b)) (define (foldl f b ) ) (foldl0'(1 2 3 4 5)) 5 (+4 6)) - (+ 5 10) Figure 96: ISL's abstract functions for list processing (2) trl+s ]N [N -X] -[List-of X] ; constructs a list by applying f to , 1, , (sub1 n) ; (build-list n f)-(list (f ) (f (-n 1))) (define (build-listnf) ...) ; [X] [XBoolean] [List-of X] - [List-of X] ; produces a list from those items on lx for which p holds (define (filter p ) ) ; [X] [List-of X] [X X - Boolean] -[List-of X] ; produces a version of that is sorted according to cmp (define (sort lx cmp) ...) ; [XY] [X-> Y] [List-of X] -> [List-of Y] ; constructs a list by applying f to each item on ; (map f (list x-1 X-n))(list (f x-1) (f x-n)) (define (map f lx) ...) ; [X] [XBoolean] [List-of X] - Boolean ; determines whether p holds for every item on lx ; (andmap p (list x-1 x-n)) -= (and (p x-1) (p x-n)) (define (andmap p lx) ...) ; [X] [XBoolean] [List-of X] - Boolean ; determines whether p holds for at least one item on lx ; (ormap p (listx-1 x-n)) -(or (p x-1) (p x-n)) (define (ormap p ) ) ; applies f from right to left to each item in lx and b ; (foldr f b (list x-1 x-n))(f x-1 (f x-n b)) (define (foldr f b ) ) (foldr0'(1 2 3 4 5)) (+1 (+2 12)) ; applies f from left to right to each item in lx and b ; (foldl f b (list x-1 x-n))(f x-n (f x-1 b)) (define (foldl f b ) ) (foldl0'(1 2 3 4 5)) 5 (+4 6)) - (+ 5 10) Figure 96: ISL's abstract functions for list processing (2)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started