notes48 - In file...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
;;;;; In file cs61a/lectures/3.0/demo1.scm (define-class (person name) (method (say stuff) stuff) (method (ask stuff) (ask self ’say (se ’(would you please) stuff))) (method (greet) (ask self ’say (se ’(hello my name is) name))) ) > (define marc (instantiate person ’marc)) > (ask marc ’say ’(good morning)) (good morning) > (ask marc ’ask ’(open the door)) (would you please open the door) > (ask marc ’greet) (hello my name is marc) Notice that an object can refer to itself by the name self ; this is an automatically-created instance variable in every object whose value is the object itself. (We’ll see when we look below the line that there are some complications about making this work.) ;;;;; In file cs61a/lectures/3.0/demo1.scm (define-class (pigger name) (parent (person name)) (method (pigl wd) (if (member? (first wd) ’(a e i o u)) (word wd ’ay) (ask self ’pigl (word (bf wd) (first wd))) )) (method (say stuff) (if (atom? stuff) (ask self ’pigl stuff) (map (lambda (w) (ask self ’pigl w)) stuff))) )
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Ask a homework question - tutors are online