;; Object oriented version of Tree ;; a preview of CS61B (define-class (tree datum children) (method (tree-map! fn) (set! datum (fn datum)) (for-each (lambda (t) (ask t 'tree-map! fn)) children)) (method (count) (if (null? children) 1 (+ 1 (count-forest children)))) ) (define (count-forest ls) (if (null? ls) 0 (+ (ask (car ls) 'count) (count-forest (cdr ls))))) (define english-kings (instantiate tree 'HenryII (list (instantiate tree 'RichardI '()) (instantiate tree 'John (list (instantiate tree 'HenryIII '()))))))