fork download
  1. ; your code goes here
  2.  
  3. ;;Global variable for the continuation
  4. (define k-global #f)
  5.  
  6. ;;We are using let* instead of let so that we can guarantee
  7. ;;the evaluation order
  8. (let* (
  9. (my-number 3)
  10. (k
  11. ;;set bookmark here
  12. (call-with-current-continuation
  13. ;;The continuation will be stored in "kont"
  14. (lambda (kont)
  15. ;;return the continuation
  16. kont))))
  17.  
  18. ;;We are using "my-number" to show that the old stack
  19. ;;frame is being saved. When we revisit the continuation
  20. ;;the second time, the value will remain changed.
  21. (display "The value of my-number is: ")
  22. (display my-number)
  23. (newline)
  24. (set! my-number (+ my-number 1))
  25.  
  26. ;;Save the continuation in a global variable.
  27. (set! k-global k)
  28. (display "test #2")
  29. (newline)
  30. )
  31.  
  32. (display "test#")
  33. (newline)
  34.  
  35. ;;Is "kontinuation" a continuation?
  36. (if (procedure? k-global)
  37. (begin
  38. (display "This is the first run, k-global is a continuation")
  39. (newline)
  40. ;;Send "4" to the continuation which goes to the bookmark
  41. ;;which will assign it to "k"
  42. (k-global 4))
  43. (begin
  44. ;;This occurs on the second run
  45. (display "This is the second run, k-global is not a continuation, it is ")
  46. (display k-global)
  47. (newline)))
Success #stdin #stdout 0.03s 4132KB
stdin
Standard input is empty
stdout
The value of my-number is: 3
test #2
test#
This is the first run, k-global is a continuation
The value of my-number is: 4
test #2