Question
Use Scheme programming language to solve the questions. 1. Write a function in-range? which takes two numbers (limits) and a list of numbers as parameters
Use Scheme programming language to solve the questions.
1. Write a function in-range? which takes two numbers (limits) and a list of numbers as parameters and returns true (#t) if each number in the list is between the given limits (i.e. greater than or equal to the first limit and less than or equal to the second). You can assume that the first limit will always be less than or equal to the second limit. Numbers can be compared using the built-in functions <, <=, >, and >=.
Examples:
(in-range? 3 12 '(5 3 9) ) #t (in-range? 3 12 '(5 13 9) ) #f (in-range? 4 4 '(4 4 4 4 4) ) #t (in-range? 3 12 '() ) #t
2. Write a function atom-count which takes an atom and a list of atoms as parameters and returns the number of times the given atom occurs in the list.
Examples:
(atom-count 'b '(a b g a b c b) ) 3 (atom-count 'g '(a b g a b c b) ) 1 (atom-count 'w '(a b g a b c b) ) 0 (atom-count 'b '() ) 0 (atom-count 'x '(x xx x xxx x xxxx x) ) 4
3. Write a function lookup which takes an atom and a list of pairs as parameters and returns an expression. Each pair in the second argument has an atom as the first entry and a Scheme value as the second. The function should find the first pair in the list whose first entry matches the given atom and then return the second half of that pair. Watch the examples closely to make sure your code doesn't add or leave out expected parentheses. If the atom is not found in the list of pairs, the function should return a special atom UNKNOWN. I still want good recursive style.
Examples:
(lookup 'b '((a 34)(b 77)(g 6)) ) 77 (lookup 'a '((a "apple")(b "boy")(g "gate")) ) "apple" (lookup 'c '((a 34)(b 77)(g 6)) ) 'UNKNOWN (lookup 'food '((lodging 250.0)(gas 98.60)(food 120.44)) ) 120.44 (lookup 15 '((12 (2 3)) (15 (3 5)) (30 (2 3 5)) (99 (3 11))) ) '(3 5) (lookup 'a '() ) 'UNKNOWN
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