Question

In racket, Given the function definition: (define (guess   a_list)                             &nbsp

In racket, Given the function definition:

(define (guess   a_list)                                     

    (if (null? a_list)

   0

   (+ 1 (guess (cdr a_list)))

))

(a) write the derivation of the following function call:  (guess ‘(3 1 2 5)) =>

(b) explain what this function is doing when given a parameter a_list (NOT the steps of execution, but the result).

Homework Answers

Answer #1

Solution:

Given function definition:

(define (guess   a_list)                                     

    (if (null? a_list)

   0

   (+ 1 (guess (cdr a_list)))

))

a.Ans:

(guess ‘(3 1 2 5))

= 1 + (guess (1 2 5))

= 1 + 1 + (guess (2 5))

= 1 + 1 + 1 + (guess (5))

= 1 + 1 + 1 + 1 + (guess ())

= 1 + 1 + 1 + 1 + 0

= 4

b.Ans:

(guess ‘(3 1 2 5))

calls the guess function here the list is [3 1 2 5]

if the list is empty then return 0

else add 1 to the recursive guess function until the list becomes 0

Finally the result will be 4 as there are 4 elements in the list.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes...
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x)...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The function should return the sum of all the integers x, x-2, x-4, x-6, etc. as long as the numbers are positive. For example, [sum-alternate 5] should evaluate to 5 + 3 + 1, and [sum-alternate 6] should evaluate to 6+4+2.
Using Dr-Racket, what is the purpose of the number function? (define (number n) (local [(define (abstract...
Using Dr-Racket, what is the purpose of the number function? (define (number n) (local [(define (abstract int) (* int 11))] (build-list n abstract))) A) Create a list of the first n multiples of 11 starting at 11. B) Create a list of the first n multiples of 11 starting at 0. C) Create a list of the first n multiples of 11 starting at 1. D) Create a list of the first 11 multiples of n starting at 1. E)...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
In racket, implement a tail-recursive function called sum-pairs that creates a new list by adding the...
In racket, implement a tail-recursive function called sum-pairs that creates a new list by adding the elements of an input list in pairs. That is the first element of the resulting list is the sum of the first two elements of the input, the second element of the resulting list is the sum of the 3rd and 4th elements of the input, and so on. If there is an odd number of elements, then the last element remains unchanged. As...
Using the derivative definition, point the derivative value for the given function f(z)=3/z^2 Find in Z0=1+i...
Using the derivative definition, point the derivative value for the given function f(z)=3/z^2 Find in Z0=1+i and write x+iy algebraically.
1) Explain what inferential statistics is used for 2) Define briefly and in your words the...
1) Explain what inferential statistics is used for 2) Define briefly and in your words the p-value 3) Provide an example where a hypothesis test would be worth doing with a null hypothesis μ1-μ2 = 0, and with an alternative hypothesis of μ1-μ2 ≠ 0 4) Explain why, in confidence intervals, when moving from a case in which the population variance is known to another in which this value is estimated from samples (sample variance), the length of the interval...
Given the following Prolog function: fn([Y], Y). fn([_|Z], Y) :- fn(Z, Y). (a) Determine what output...
Given the following Prolog function: fn([Y], Y). fn([_|Z], Y) :- fn(Z, Y). (a) Determine what output will be produced if we run the query:   fn([1, 2, 3], Y). (b) Explain what the function fn does (do NOT list steps, give the final result).
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT