DOC PREVIEW
MIT 6 001 - Recitation 18 Message-Passing Objects

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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

MIT 6 001 - Recitation 18 Message-Passing Objects

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Recitation 18 Message-Passing Objects
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recitation 18 Message-Passing Objects and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recitation 18 Message-Passing Objects 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?