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

Language= SCHEME Define a procedure called make-list that implements the List AD

ID: 3734616 • Letter: L

Question

Language= SCHEME

Define a procedure called make-list that implements the List ADT using an object oriented design in Scheme. The make-list procedure should return a list object. (Note: The List object you'll create is different from a native Scheme list, however, the backing implementation of the List object may use a standard list).

The list object should have the following behaviour:

(remove i) - removes and returns the item at index i from the list

For the functions, bad inputs (i.e. invalid indices) should be checked. Return #f for any operation that should return a value but fails. Your code should be written in such a way that the following interactions would be valid :

If L1 = (a b c d)

((L1 'remove) 1) should return b.

Note: List should be modified as well so L1 will be = (a c d)

Explanation / Answer

Source code :

(define L1 (make-list))

(define L2 (make-list))

(display "L1: ")((L1 'print))                  ; prints => L1: ()

(display "L2: ")((L2 'print))                  ; prints => L2: ()

((L1 'add) 0 'a)

((L1 'add) 1 'b)

((L1 'add) 2 'c)

((L1 'add) 3 'd)

(display "L1: ")((L1 'print))                  ; prints => L1: (a b c d)

((L2 'add) 0 ((L1 'get) 2))

(display "L2: ")((L2 'print))                  ; prints => L2: (c)