;;;Exercise 3.37
(define (c+ x y)
(let ((z (make-connector)))
(adder x y z)
z))
(define (c- x y)
(let ((z (make-connector)))
(adder z y x)
z))
(define (c* x y)
(let ((z (make-connector)))
(multiplier x y z)
z))
(define (c/ x y)
(let ((z (make-connector)))
(multiplier z y x)
z))
(define (cv x)
(let ((z (make-connector)))
(constant x z)
z))
(define (celsius-fahrenheit-converter x)
(c+ (c* (c/ (cv 9) (cv 5))
x)
(cv 32)))
(define C (make-connector))
(define F (celsius-fahrenheit-converter C))
(probe "Celsius temp" C)
(probe "Fahrenheit temp" F)
;;;Test
(set-value! C 25 'user)
(set-value! C 26 'user)
(forget-value! C 'user)
(set-value! F 24 'user)
The output is:
#<procedure:me>
#<procedure:me>
Probe: Celsius temp = 25
Probe: Fahrenheit temp = 77
'done
Error:connector.rkt:15:13: Contradiction (25 26)
when encounter the error, the execution is stopped. If we change the test code to:
;;;Test
(set-value! C 25 'user)
;(set-value! C 26 'user)
(forget-value! C 'user)
(set-value! F 24 'user)
The output is:
#<procedure:me>
#<procedure:me>
Probe: Celsius temp = 25
Probe: Fahrenheit temp = 77
'done
Probe: Celsius temp = ?
Probe: Fahrenheit temp = ?
'done
Probe: Fahrenheit temp = 24
Probe: Celsius temp = -40/9
'done