;; 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. ;; 10.5 An Application: Adding Explanatory Output to Mini-Scheme (define unparse (lambda (ast) (ast 'unparse))) (define display-times (lambda (output count) (if (= count 0) 'done (begin (display output) (display-times output (- count 1)))))) (define write-with-at (lambda (thing indicator level) (display-times "| " (- level 1)) (display "+-") (display indicator) (display " ") (write thing) (newline))) (define blank-line-at (lambda (level) (display-times "| " level) (newline))) ;; new code, not in the book (define blank-line ;like blank-line-at but knows which level (lambda () (blank-line-at (get-level repl-state)))) (define write-with ;like write-with-at but knows which level (lambda (obj indicator) (write-with-at obj indicator (get-level repl-state)))) (define evaluate ; based on page 322's evaluate-in-at (lambda (ast) (blank-line) (set-level! repl-state (+ 1 (get-level repl-state))) (write-with (unparse ast) "<") (let ((value (ast 'evaluate))) (write-with value ">") (set-level! repl-state (- (get-level repl-state) 1)) value))) (define evaluate-additional ; based on page 322's evaluate-additional-in-at (lambda (ast) (blank-line) (write-with (unparse ast) "-") (ast 'evaluate)))