Question: USING SCHEME PROGRAMMING LANGUAGE [20 marks] Define a procedure called make-list that implements the List ADT using an object oriented design in Scheme. The make-list
USING SCHEME PROGRAMMING LANGUAGE
![USING SCHEME PROGRAMMING LANGUAGE [20 marks] Define a procedure called make-list](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3a38d35827_14866f3a38cad76b.jpg)
[20 marks] 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 standard list, however, the backing implementation of the List object may use a standard list) The list object should have the following behaviours (size) - returns an integer equal to the number of items in the list (get i) - returns the element stored at index i in the list (set i x) - modifies index i in the list to hold item x (add i x) - adds item x at index i in the list . . . . . (remove i) - removes the item at index i from the list * (print) - displays the list For each of the functions, bad inputs (such as invalid indices) should be checked. Return #f for any operation that should return a value but fails. Your code should support the following interactions for creating, modifying and diplaying the List: (define Ll (make-list)) (define L2 (make-list)) (display "Ll: ")( (Ll 'print)) (display "L2: ")((L2 'print)) ((L1 'add) 0 'a) ; prints- L1:) ; printsL2: ) ((L1 'add) 2 'c) ((L1 'add) 3 'd) (display "Ll: ")( (Ll 'print)) (L2 'add) 0 ((Ll "get) 2)) ((Li set) 2 'x) (L2 'add) 1 'z) ((L1 'remove) 1) prints-Ll (a b c d) ((L1 'add) 0 1) (display "Ll: "((Ll 'print)) (display "L2: " ) ( (L2 ' print)) (display "size of Ll: " (display (Ll size)) (newline) prints ->size of Ll: 4 (display "size of L2: ") (display ((1.2 'size))) (newline) ; prints-> size of L2: 3 ; prints > Ll: (1 a x d) prints ->L2: (c y z) [20 marks] 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 standard list, however, the backing implementation of the List object may use a standard list) The list object should have the following behaviours (size) - returns an integer equal to the number of items in the list (get i) - returns the element stored at index i in the list (set i x) - modifies index i in the list to hold item x (add i x) - adds item x at index i in the list . . . . . (remove i) - removes the item at index i from the list * (print) - displays the list For each of the functions, bad inputs (such as invalid indices) should be checked. Return #f for any operation that should return a value but fails. Your code should support the following interactions for creating, modifying and diplaying the List: (define Ll (make-list)) (define L2 (make-list)) (display "Ll: ")( (Ll 'print)) (display "L2: ")((L2 'print)) ((L1 'add) 0 'a) ; prints- L1:) ; printsL2: ) ((L1 'add) 2 'c) ((L1 'add) 3 'd) (display "Ll: ")( (Ll 'print)) (L2 'add) 0 ((Ll "get) 2)) ((Li set) 2 'x) (L2 'add) 1 'z) ((L1 'remove) 1) prints-Ll (a b c d) ((L1 'add) 0 1) (display "Ll: "((Ll 'print)) (display "L2: " ) ( (L2 ' print)) (display "size of Ll: " (display (Ll size)) (newline) prints ->size of Ll: 4 (display "size of L2: ") (display ((1.2 'size))) (newline) ; prints-> size of L2: 3 ; prints > Ll: (1 a x d) prints ->L2: (c y z)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
