# CSI2120 Lab 11-List Processing with Error Checking Solved

30.00 \$ 15.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

Rate this product

Write a top-level define absDiff that calculates the absolute difference of the corresponding elements of two lists. The function also evaluates to a list. Check if the list have the same length otherwise return an error. You are given the auxiliary routine loop.

(define (loop LA LB)Â  (if (or (null? LA) (null? LB))Â Â Â Â Â  ‘()Â Â Â Â Â  (cons (abs (- (car LA) (car LB))) (loop (cdr LA) (cdr LB)))))Â ; Examples:;; (absDiff â€˜(1 3 5 6) â€˜(3 5 2 1));Â  =>Â Â  (2 2 3 5);; (absDiff ‘(1 3 5 6 7) ‘(3 5 2 1)) ; => “List have different length”;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

### Exercise 2: Advanced List Processing

Change the above top-level define and auxillary function such that it also works when the two input lists are not the same length by assuming that the missing elements in the shorter list have the value of 0. The result will be of length equal to the longer list.

; Example:;; (absDiffA â€˜(1 3 5 6 2 5) â€˜(3 5 2 1)); =>Â Â Â  (2 2 3 5 2 5) ;; (absDiffA â€˜(1 3 5 6) â€˜(3 5 2 1 2 5)); =>Â Â Â  (2 2 3 5 2 5) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

### Exercise 3: Local Definitions

Change the definition of the following function min-list to not use any auxillary helper function. Hint: Use local definitions.

; Example:;; (min-list ‘(4 8 9 2 8)); => 2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(define (min-list x)Â  (if (null? x)Â Â Â Â Â  xÂ Â Â Â Â  (min-list-aux (car x)(cdr x))))Â (define (min-list-aux e l)Â  (condÂ Â  ((null? l) e)Â Â  ((> e (car l))Â Â Â  (min-list-aux (car l)(cdr l)))Â Â  (else (min-list-aux e (cdr l)))))

### Exercise 4 and Quiz: Let Bindings

Please hand-in the answer to this question on Virtual Campus during your lab session but at the latest by Friday 6:00pm! Remember, your submission will only count if you have signed the lab attendance sheet.

Fill the gaps in the following expression with the appropriate form of let.

; (____________ ((f (lambda (a b); Â Â Â Â Â  (_____________ ((b (* b b)));Â Â Â Â Â Â Â Â Â Â Â Â Â  (_____________ ((a (* a a)) (b (- b a))); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  (if (< a b);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  (f b a));Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  (list a b))))))) (f 1 2));; => ‘(9 -8);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

• Lab11-x2xvtd.zip