;;;;; 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))) )
This is the end of the preview.
access the rest of the document.