DOC PREVIEW
MIT 6 001 - Higher-Order Procedures

This preview shows page 1 out of 4 pages.

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

Unformatted text preview:

6.001, Spring 2004—Recitation 6 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.001—Structure and Interpretation of Computer ProgramsSpring 2004Recitation 6Higher-Order ProceduresScheme1. Special Forms(a) let - (let bindings body)Binds the given bindings for the duration of the body. The bindings is a list of (namevalue) pairs. The body consists of one or more expressions which are evaluated in orderand the value of last is returned.From last time(define (make-units C L H)(list C L H))(define get-units-C car)(define get-units-L cadr)(define get-units-H caddr)(define (make-class number units)(list number units))(define get-class-number car)(define get-class-units cadr)(define (get-class-total-units class)(let ((units (get-class-units class)))(+ (get-units-C units)(get-units-L units)(get-units-H units))))(define (same-class? c1 c2)(= (get-class-number c1) (get-class-number c2)))1. Write constructor that returns an empty schedule.(define (empty-schedule)Order of growth in time, space?6.001, Spring 2004—Recitation 6 22. Write a procedure that when given a class and a schedule, returns a new schedule includingthe new class:(define (add-class class schedule)Order of growth in time, space?3. Write a procedure that computes the total number of units in a schedule.(define (total-scheduled-units sched)Order of growth in time, space?4. Write a procedure that drops a particular class from a schedule.(define (drop-class sched classnum)Order of growth in time, space?5. Implement the freshman credit limit by taking in a schedule, and removing classes until thetotal number of units is less than max-credits.(define (credit-limit sched max-credits)Order of growth in time, space?6.001, Spring 2004—Recitation 6 3HOPs(define (make-student number sched-checker)(list number (list) sched-checker))(define get-student-number car)(define get-student-schedule cadr)(define get-student-checker caddr)(define (update-student-schedule student schedule)(if ((get-student-checker student) schedule)(list (get-student-number student)schedule(get-student-checker student))"invalid schedule"))6. Finish the call to make-student to limit the student to taking at least 1 class.(make-student 5759044677. Finish the call to make-student to create a first-term freshman (limited to 54 units).(make-student 5759044678. Write a procedure that takes a schedule and returns a list of the names of the classes in theschedule. Use map.(define (class-names schedule)(map9. Rewrite drop-class to use filter.10. Rewrite total-scheduled-units to use map and fold-right.6.001, Spring 2004—Recitation 6 411. Rewrite credit-limit to use


View Full Document

MIT 6 001 - Higher-Order Procedures

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 Higher-Order Procedures
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 Higher-Order Procedures 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 Higher-Order Procedures 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?