; file: show.scm ; author: robert keller ; purpose: define the "show" wrapper ; For any expression exp ; (show exp) ; will print the expression exp after a message "showing value of " and ; return the value of exp. ; It can thus be wrapped around any expression that is evaluated for a value. ; ; Alternatively, ; (show-message msg exp) ; will print a specified message before the value ; ; The result of this wrapped expression is the same as the value ; of the expression itself there will be a side-effect of displaying ; the expression and its value. ; ; Once your program is debugged, the wrapped expression can be replaced ; with the original expression. ; ; Caution: This file adds to the following to the namespace: ; show, show-message, show-wrapper, show-message-wrapper (define (show-wrapper msg1 value) (begin (display "showing value of ") (display msg1) (display ": ") (display value) (newline) value)) (define (show-message-wrapper msg value) (begin (display msg) (display ": ") (display value) (newline) value)) (define-macro (show expr) `(show-wrapper ',expr ,expr)) (define-macro (show-message msg expr) `(show-message-wrapper ,msg ,expr))