Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. (define make-counter
  2. (let ((glob 0))
  3. (lambda ()
  4. (let ((loc 0))
  5. (lambda ()
  6. (set! loc (+ loc 1))
  7. (set! glob (+ glob 1))
  8. (list loc glob))))))
  9.  
  10. > (define counter1 (make-counter))
  11. counter1
  12.  
  13.  
  14. > (define counter2 (make-counter))
  15. counter2
  16.  
  17. > (counter1)
  18. (1 1)
  19.  
  20. > (counter1)
  21. (2 2)
  22.  
  23. > (counter2)
  24. (1 3)
  25.  
  26. > (counter1)
  27. (3 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement