Answered step by step
Verified Expert Solution
Question
1 Approved Answer
SICP: Scheme Quetion. (a) The exponent function can be defined as exp (x , n) exp (x, n-1) , if n > 0 , if
SICP: Scheme Quetion.
(a) The exponent function can be defined as exp (x , n) exp (x, n-1) , if n > 0 , if n 0 = x * i. Write a Scheme function which implements exp as defined above. Your function must generate a Recursive process. [4 marks] ii. Write another version of exp which generates an Iterative process [5 marks] (b) Write a Scheme procedure, called enum-downfrom, that takes a positive integer n and returns a list of integers from n down to zero inclusive. So, for example: (enum-downfrom 4) returns the list (4 3 2 1 0) [3 marks] (c) Write a Scheme procedure, called drop, which takes a positive integer parameter n and a list parameter ls and returns a list consisting of all but the first n elements of 1s. If 1s is less than n elements long then drop should just return the empty list. So, for example: (drop 3 Clist 3 4567 8)) will return the list (6 7 8) and: (drop 10 (list 1 2 3)) will return the empty list: () [4 marks] (d) Write a Scheme procedure called sfunc which takes in two procedural values: f and g and returns a procedure which takes a value x and returns: fx) + g(x). So, for example, given the following definitions (define (square x) (* x x)) (define (inc x) (+ x 1)) (define si (sfunc square inc)) The call: (si 4) - (16 5) 21 [4 marks]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