WXME0104 ## wxtextwxtabwxmediawximage$(lib "comment-snip.ss" "framework")+(lib "collapsed-snipclass.ss" "framework")drscheme:sexp-snipdrscheme:number,(lib "number-snip.ss" "drscheme" "private")"drscheme:vertical-separator-snip%wxbaddrscheme:xml-snip(lib "xml-snipclass.ss" "xml")drscheme:scheme-snip"(lib "scheme-snipclass.ss" "xml")wxloc'K ZZZZ€ÿ€ÿ€ÿ StandardK Courier New ZZZZ€ÿ€ÿ€ÿF?ð\ZZZ?ð?ð?ð"€‹"Matching Parenthesis StyleF?ð\ZZZ?ð?ð?ð"€‹"F?ð\ZZZ?ð?ð?ð(drscheme:check-syntax:keywordF?ð\ZZZ?ð?ð?ð(F?ðZZZZ?ð?ð?ð€ø@'drscheme:check-syntax:unbound-variableF?ðZZZZ?ð?ð?ð€ø@F?ðZZZZ?ð?ð?ð$$€Œ%drscheme:check-syntax:bound-variableF?ðZZZZ?ð?ð?ð$$€Œ drscheme:check-syntax:primitiveF?ðZZZZ?ð?ð?ð$$€ŒF?ðZZZZ?ð?ð?ð3€‡'drscheme:check-syntax:constantF?ðZZZZ?ð?ð?ð3€‡'F?ðZZZZ?ð?ð?ð€„<$drscheme:check-syntax:baseF?ðZZZZ?ð?ð?ð€„<$F?ðZZZZ?ð?ð?ð?ð?ð?ðXMLF?ðZZZZ?ð?ð?ð?ð?ð?ðG?ðZZZZ?ð?ð?ð?ð?ð?ðF?ðZZZZ?ð?ð?ðPP€øG?ðZZZZ?ð?ð?ðPP€øG?ðZZZZ?ð?ð?ðdK ZZZZ€ÿ€ÿ€ÿK Courier New ZZZZ€ÿ€ÿ€ÿF?ð\ZZZ?ð?ð?ð"€‹"F?ð\ZZZ?ð?ð?ð(F?ðZZZZ?ð?ð?ð€ø@F?ðZZZZ?ð?ð?ð$$€ŒF?ðZZZZ?ð?ð?ð3€‡'F?ðZZZZ?ð?ð?ð€„<$F?ðZZZZ?ð?ð?ð?ð?ð?ðG?ðZZZZ?ð?ð?ð?ð?ð?ðF?ðZZZZ?ð?ð?ðPP€øG?ðZZZZ?ð?ð?ðPP€øG?ðZZZZ?ð?ð?ðdF?ð\ZZZ?ð?ð?ð€¯F?ðZZ^Z?ð?ð?ð€ÿF?ð\ZZZ?ð?ð?ð€¯F?ðZZ^Z?ð?ð?ð€ÿ ;; global counter variable (define counter 0)  ;;count: --> num +;; adds one to the global counter variable  ;; and returns the new value. (define (count)  (begin ! (set! counter (add1 counter))  counter))  "count:" (count) (count) (count)   ;;count2: --> num +;; adds one to the global counter variable  ;; and returns the new value. (define (count2)  (begin ! (set! counter (add1 counter))  counter))    "count2:" (count2) "count:" (count)  "count2:" (count2)  !;;countFac: --> (lambda: --> num) .;; factory to that returns a counter function, -;; which increments and returns the new value 1;; of a counter. The counter is initialized to  ;; zero. (define (countFac)  (local  [(define counter 0)]  (lambda ()  (begin % (set! counter (add1 counter))  counter))))    5The following code produces inter-dependent counters.  Why?  3Try it by commenting out the above code with a box  $and uncommenting the following code.  Note: it's contract is correct.  é!;;countFac: --> (lambda: --> num) .;; factory to that returns a counter function, -;; which increments and returns the new value 1;; of a counter. The counter is initialized to  ;; zero. (define countFac  (local  [(define counter 0)]  (lambda ()  (lambda ()  (begin ' (set! counter (add1 counter))  counter)))))  x/The following code won't work either. Why not?  # Note: it's contract is correct. Ë!;;countFac: --> (lambda: --> num) .;; factory to that returns a counter function, -;; which increments and returns the new value 1;; of a counter. The counter is initialized to  ;; zero. (define (countFac)  (lambda ()  (local  [(define counter 0)]  (begin % (set! counter (add1 counter))  counter))))   "countFac test cases:"  (define countF1 (countFac))   "countF1:"  (countF1)  (countF1)  (countF1)   (define countF2 (countFac))   "countF2:"  (countF2)  "countF1:"  (countF1)  "countF2:"  (countF2)   .;; Counter structure that represents a counter ;; tied to a total count.  2;; inc adds one to the total count and returns it. (;; reset resets the total count to zero.  ;; total returns the total count 1;;(make-Counter (inc: --> num) (reset: --> void)) )(define-struct Counter (inc total reset))  ;;depend-countFac --> Counter ;; Factory for a Counter struct .;; All counters made have the same total count (define depend-countFac  (local  [(define total 0)]  (lambda ()  (make-Counter  (lambda ()   (begin  $ (set! total (add1 total))  total))  (lambda () total)  (lambda ()   (set! total 0))))))   "multiCountFac test cases:"  (define c1 (depend-countFac)) (define c2 (depend-countFac)) (define c3 (depend-countFac))   ((Counter-inc c1)) ((Counter-inc c2)) ((Counter-inc c3)) ((Counter-inc c1)) ((Counter-reset c2)) ((Counter-inc c1)) ((Counter-inc c2)) ((Counter-inc c3))    ;;indep-countFac --> Counter ;; Factory for a Counter struct /;; All counters made have their own total count (define indep-countFac  (lambda ()  (local  [(define total 0)]  (make-Counter  (lambda ()   (begin  $ (set! total (add1 total))  total))  (lambda () total)  (lambda ()   (set! total 0))))))   "indep-countFac test cases:"  (define c4 (indep-countFac)) (define c5 (indep-countFac)) (define c6 (indep-countFac))   ((Counter-inc c4)) ((Counter-inc c5)) ((Counter-inc c6)) ((Counter-inc c4)) ((Counter-reset c5)) ((Counter-inc c4)) ((Counter-inc c5)) ((Counter-inc c6))