Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the following functions in Scheme using filter, fold-left and map. DO

ID: 3750336 • Letter: I

Question

Implement the following functions in Scheme using filter, fold-left and map. DO NOT use recursive denition for this problem. 1/2 a) (5pt)Deneafunction allEven,whichtakesalistofintegernumbers,andreturnsalistcontainingonly the even numbers from the original list. For this problem, assume that 0 is neither odd nor even. Examples: (allEven 0(0 1 2 3 4)) should return (2 4). b) (5pt) Dene a function checksum, which takes a list of integers, as well as one integer (as the expected sum). The function returns #t if the list sums up to the integer or #f if the list does not sum up to the integer. For example, (checksum 0(1 2 3 4) 10) should return #t, (checksum 0(1 2 3 4) 8) should return #f. c) (5pt) Dene a function zip, which takes a list of several lists with the same length, and returns another list of lists where the n-th list is composed by the n-th elements of each list. For example, (zip 0((1 2) (3 4))) should return ((1 3) (2 4)).

Explanation / Answer

What we want is a succinct solution to reverse a list in Scheme using a foldl call and a different solution using a foldr call, as defined:

and

The astute person will observe that the foldl implementation is tail-recursive because the returned value is computed as each recursive step is called - at the last step the entire answer is already computed and simply returned up the chain.

The foldr implementation is not tail-recursive because it must build the returned value by using the values that are passed back up the recursive chain.

Therefore, the two Scheme implementations that we are interested in should be in the following form,

and

The end goal is to be able to call the following,