diff options
Diffstat (limited to 'js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.0/count.scm')
-rw-r--r-- | js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.0/count.scm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.0/count.scm b/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.0/count.scm new file mode 100644 index 0000000..b68ff2d --- /dev/null +++ b/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.0/count.scm @@ -0,0 +1,32 @@ +(define-class (counter) + (instance-vars (count 0)) + (method (next) + (set! count (+ count 1)) + count) ) + +(define-class (counter2) + (instance-vars (count 0)) + (class-vars (total 0)) + (method (next) + (set! total (+ total 1)) + (set! count (+ count 1)) + (list count total))) + +(define-class (counter3) + (instance-vars (count 0)) + (class-vars (total 0) (counters '())) + (initialize (set! counters (cons self counters))) + (method (next) + (set! total (+ total 1)) + (set! count (+ count 1)) + (list count total))) + +(define c11 (instantiate counter)) +(define c12 (instantiate counter)) + +(define c21 (instantiate counter2)) +(define c22 (instantiate counter2)) + +(define c31 (instantiate counter3)) +(define c32 (instantiate counter3)) + |