Question: HELP FOR RACKET LANGUAGE For Problem 5 of Homework 2, you wrote a function named in-range? that tests to see if two values are within
HELP FOR RACKET LANGUAGE
For Problem 5 of Homework 2, you wrote a function named in-range? that tests to see if two values are within a specified tolerance. When we work in engineering settings with such tolerances, the *epsilon* value is often fixed for most of our tests. Passing *epsilon* to the function every time we call it is inconvenient, but making *epsilon* a global variable creates bigger problems. Write a Racket function named in-range-of that takes one number as an argument: the epsilon to use as a tolerance. in-range-of returns as its value a function that takes two number arguments. The returned function returns true if the difference between its arguments is less than epsilon, and false otherwise. For example:
> ((in-range-of? 0.1) 4.95 5.0) #t > ((in-range-of? 0.1) 5.0 4.95) ;; works both ways #t > (define within-0.01? (in-range-of? 0.01)) > (within-0.01? 4.95 5.0) ;; not anymore! #f > (within-0.01? 5.0 4.99) #t
(define in-range-of? (lambda (epsilon) 'YOUR-CODE-HERE )) ; ----- tests ------- (check-true ((in-range-of? 0.1) 4.95 5.0)) (check-false ((in-range-of? 0.1) 5.0 4.85)) (define within-0.01? (in-range-of? 0.01)) (check-false (within-0.01? 4.95 5.0)) ;; not anymore! (check-true (within-0.01? 5.0 4.99))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
