This essay has been submitted by a student. This is not an example of the work written by professional essay writers.
Uncategorized

CS FUNCTION

Pssst… we can write an original essay just for you.

Any subject. Any type of essay. We’ll even meet a 3-hour deadline.

GET YOUR PRICE

writers online

CS FUNCTION

Q.1) Complete the function (nearest -even target L) . it consumes a Num and a (list of Int).

Of all the items in L that are even , it returns the one that has the smallest distance to target

In the case of a tie , pick the value closer to the left in the list .

 

For example , if  the target is 15 , the distance between 12 and 15 is 3, and the distance between 22 and 15 is 7 , So considering 12 and 22 , the number with the smaller distance to 15 is 12 ,

So ( nearest-even 15 ( list 12 15 17 19 22)) => 12.

The distance between 15 and 17 is only 2 , but since 17 is odd , we do not consider it.

You may write as much of the design recipe as you like . Only your code will be marked .

;; (nearest-even target L) Return the even value in L that is closest to target.

;; nearest-even: Num (listof Int) -> Int

;; Requires: there is at least one even value in L.

 

;(define (nearest-even target L)

Hint: You may use the function abs to calculate absolute value

 

Q.2) Read the function (trace-me) and fill in the blanks:

;; (a) * The type of base must be: ……..

;;     * Choose any appropriate value for base.

;(define base ……..)

 

;; (b) Given that this is a valid call to trace-me,

;; (trace-me (list 2 3 5))

;; * Write the contract for trace-me.

;; ……..

 

;(define (trace-me L)

;  (string-append

;   “*”

;   (foldr G base L)))

 

;; (c) Write the contract for G.

;; ……..

 

;; (d) Trace the expression below as far as possible.

;;     Image that G is defined, but do not expand any call to G.

;;     A correct final result will get full marks.

;;     You may include intermediate steps.

;; (trace-me (list 2 3 5))

;; => ……..

  Remember! This is just a sample.

Save time and get your custom paper from our expert writers

 Get started in just 3 minutes
 Sit back relax and leave the writing to us
 Sources and citations are provided
 100% Plagiarism free
error: Content is protected !!
×
Hi, my name is Jenn 👋

In case you can’t find a sample example, our professional writers are ready to help you with writing your own paper. All you need to do is fill out a short form and submit an order

Check Out the Form
Need Help?
Dont be shy to ask