notes08s - [Solutionsv1.0...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS61A Notes 11 – Where The Objects Roam [Solutions v1.0] Taste The Rainbow (or: Dinner Is Not Ready) (define-class (bag) (instance-vars (skittles ‘())) (method (tag-line) ‘taste-the-rainbow) (method (add s) (set! skittles (cons s skittles))) (method (take) (let ((first (car skittles))) (set! skittles (cdr skittles)) first)) (method (take-color color) (let ((found (find (lambda(s) (eq? color (ask s ‘color))) skittles))) (set! skittles (remove found skittles)) found))) Pairs Are Objects Too (or: The Third Way To Do  cons ) (define (make-oop-list ls) (cond ((null? ls) (instantiate the-null-list)) (else (instantiate cons-pair (car ls) (make-oop-list (cdr ls)))))) (define-class (cons-pair the-car the-cdr) (method (length) (+ 1 (ask the-cdr 'length))) (method (listify) (cons the-car (ask the-cdr 'listify))) (method (map op) (instantiate (op the-car) (ask the-cdr ‘map op))) (method (map! op) (set! the-car (op the-car)) (ask the-cdr 'map op)) (method (accumulate comb init)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/07/2010 for the course COMPUTER S 61A taught by Professor Harvey during the Spring '06 term at Berkeley.

Page1 / 2

notes08s - [Solutionsv1.0...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online