t-call-cc.scm 801 B

12345678910111213141516171819202122232425262728293031
  1. (let ((set-counter2 #f))
  2. (define (get-counter2)
  3. (call/cc
  4. (lambda (k)
  5. (set! set-counter2 k)
  6. 1)))
  7. (define (loop counter1)
  8. (let ((counter2 (get-counter2)))
  9. (set! counter1 (1+ counter1))
  10. (cond ((not (= counter1 counter2))
  11. (error "bad call/cc behaviour" counter1 counter2))
  12. ((> counter1 10)
  13. #t)
  14. (else
  15. (set-counter2 (1+ counter2))))))
  16. (loop 0))
  17. (let* ((next #f)
  18. (counter 0)
  19. (result (call/cc
  20. (lambda (k)
  21. (set! next k)
  22. 1))))
  23. (set! counter (+ 1 counter))
  24. (cond ((not (= counter result))
  25. (error "bad call/cc behaviour" counter result))
  26. ((> counter 10)
  27. #t)
  28. (else
  29. (next (+ 1 counter)))))