STUDENT NAME: 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.001—Structure and Interpretation of Computer ProgramsFall 2004Recitation 18Message-Passing ObjectsScheme1. Special Formscase - (case expr c lauses)Works like cond, except the test of each clause is a list of numbers and symbols to compareagainst the value of expr.ProblemsA message-passing object definition:(define (make-binary-oper ation name o p)(lambda (message)(case message((NAME)name)((OPERATE)(lambda (a b)(op a b)))(else(error "binop can’t" message)))))(define binop (make-binary-opera tion ’glue ( lambda (x y) (append x y))))((binop ’OPERATE) ’(1) ’(2))1. Stack object implementation(a) Complete the skeleton for the stack object given below. The skeleton comprises every-thing but the method definitions.(define (make-stack)(let ( (vals ’()))STUDENT NAME: 2(b) Add a method called EMP TY? which returns #t if the stack is empty.(c) Add a method called CLEAR which empties the stack of any elements it may contain.(d) Add a method called PEEK which return s the top element of the stack, leaving the stackunchanged. If the stack is empty, s ignal a “stack underflow” error.(e) Add a method called PUSH which allows an element to be added to the top of the stack.(f) Add a method called POP which removes and returns the top element of the stack.Remember to program defensively.2. Write a procedure called push-all which takes a stack and a list and pushes all the elementsof the list onto the stack. It should return the stack.(define (push-all stack lst)3. Write a procedure called pop-all which takes a stack and pops elements off it u ntil it becomesempty, adding each element to the output list.(define (pop-all stack)4. Write reverse.(define (reverse
View Full Document