lecture8 OOP - ; ;Lecture 8 ;part1 ; (define-class (complex...

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

View Full Document Right Arrow Icon
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;Lecture 8 ;;;part1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-class (complex real-part imag-part) (method (magnitude) (sqrt (+ (* real-part real-part) (* imag-part imag-part)))) (method (angle) (atan (/ imag-part real-part))) ) ;;;=========================== STk> (load "obj.scm") Okay Stk> (load "complex.scm") okay STk> (define c (instantiate complex 3 4)) c STk>(ask c 'magnitude) 5 STk> (ask c ’real-part) 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;part2 (define-class (counter) (instance-vars (count 0)) (method (next) (set! count (+ count 1)) count) )
Background image of page 1

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

View Full DocumentRight Arrow Icon
;;;;= = = = = = = = = = = = = = = STk> (load "counter.scm") okay STk> (define c1 (instantiate counter)) c1 Stk> (ask c1 ’next) 1 STk> (ask c1 ’next) 2 STk> (ask c1 ’next) 3 Stk> (define c2 (instantiate counter)) c2 STk> (ask c2 ’next) 1 STk> (ask c1 ’next) 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; STk>(define-class (doubler) (method (say stuff) (se stuff stuff))) --doubler STk> (define dd (instantiate doubler)) d STk> (ask dd ’say ’hello) (hello hello)
Background image of page 2
(ask dd ’say ’(hi there) 'there) (hi there hi there) STk> (ask dd ’say ’(she said)) (she said she said) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-class (counter) (instance-vars (count 0)) (class-vars (total 0)) (method (next) (set! total (+ total 1))
Background image of page 3

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

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

This note was uploaded on 03/24/2010 for the course CS 61 taught by Professor T during the Spring '10 term at Louisiana College.

Page1 / 10

lecture8 OOP - ; ;Lecture 8 ;part1 ; (define-class (complex...

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

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