Question: I have a function in racket language that I can not figure out why the values are negative, I get the correct numbers but they

I have a function in racket language that I can not figure out why the values are negative, I get the correct numbers but they are negative.

This assignment is in DrRacket, here is the question:

makeSmasher - takes as input a list M of three numbers. It then builds and returns a

Smashing function based on M.

The Smashing function that is produced (by your function makeSmasher) would have the property that it takes as input a list, and returns the

smashed version of that list. Smashing

a list means doing the following sequence of operations to each item in a list:

a. add the first element in M, then

b. multiply by the second element in M, then

c. subtract the third element in M.

For example, if "makeSmasher" was called as follows:

(makeSmasher '(8 3 7))

a function would be produced that takes as input a list and returns the "mangled" version,

based on the list '(8 3 7).

For example, if the original call had been made as follows:

(define C (makeSmasher '(8 3 7)))

then the produced function C would behave as follows:

(C '(4 8 2 9)) *** would return (29 41 23 44)

(C '(-2 3))*** would return (-8 72)

Your task is just to write makeSmasher, not "C".

Of course, makeSmasher should work for ANY input list, not just (8 3 7).

Generally speaking, you can only use the functions defined in the notes or in exercises

, or that we have used in class. You cannot use built-in functions which would make the problems trivial.

However,modulo and quotient may be used as needed.

Here is my code:

(define (smasherHelper n m o L) (if (null? L) empty (cons ((makeSmasher n m o) (car L)) (smasherHelper n m o (cdr L)))))

;((makeSmasher 8 3 7) '(4 8 2 9)) (define (makeSmasher n m o) (lambda (L) (if (list? L) (smasherHelper n m o L) (- o (* m (+ n L))))))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!