Skip to content
Browse files

add: 3.35

  • Loading branch information...
1 parent 0e123af commit 0934535963f070932b6b436a5feaac5d8493cc73 @qiao committed
Showing with 26 additions and 0 deletions.
  1. +26 −0 chapter3/3.35.scm
View
26 chapter3/3.35.scm
@@ -0,0 +1,26 @@
+(define (squarer a b)
+ (define (process-new-value)
+ (if (has-value? b)
+ (if (< (get-value b) 0)
+ (error "square less than 0 -- SQUARER" (get-value b))
+ (set-value! a
+ (sqrt (get-value b))
+ me))
+ (if (has-value? a)
+ (set-value! b
+ (* (get-value a) (get-value a))
+ me))))
+ (define (process-forget-value)
+ (forget-value! a)
+ (forget-value! b)
+ (process-new-value))
+ (define (me request)
+ (cond ((eq? request 'I-have-a-value)
+ (process-new-value))
+ ((eq? request 'I-lost-my-value)
+ (process-forget-value))
+ (else
+ (error "Unknown request -- SQUARER" request))))
+ (connect a me)
+ (connect b me)
+ me)

0 comments on commit 0934535

Please sign in to comment.
Something went wrong with that request. Please try again.