;; This file contains excerpts from the textbook Concrete ;; Abstractions: An Introduction to Computer Science Using Scheme, by ;; Max Hailperin, Barbara Kaiser, and Karl Knight, Copyright (c) 1998 ;; by Brooks/Cole Publishing Company. This file may not be reproduced ;; or redistributed other than for use with that textbook. ;; From chapter 14: (define-class 'item-list object-class '(item-vector num-items) '( ;; intended for public consumption: add display total-price delete choose empty? ;; intended for private, internal use: grow )) (class/set-method! item-list-class 'init (lambda (this) (item-list/set-item-vector! this (make-vector 10)) (item-list/set-num-items! this 0))) (class/set-method! item-list-class 'add (lambda (this item) (let ((num-items (item-list/get-num-items this)) (item-vector (item-list/get-item-vector this))) (if (= num-items (vector-length item-vector)) (begin (item-list/grow this) (item-list/add this item)) (begin (vector-set! item-vector num-items item) (item-list/set-num-items! this (+ num-items 1)) 'added))))) (define-class 'item object-class '(price) '( ;; intended for public consumption: price display input-specifics revise-specifics)) (class/set-method! item-class 'init (lambda (this price) (item/set-price! this price))) ;; From chapter 13: (define from-to-do (lambda (start stop body) (if (> start stop) 'done (begin (body start) (from-to-do (+ 1 start) stop body))))) ;; Partial solution to exercise 14.8: (class/set-method! item-class 'price (lambda (this) (item/get-price this)))