fork download
  1. #| stackoverflow.com/questions/34299077/
  2. execute-following-call-cc-exp/34314930#34314930
  3.  
  4. (let/cc done
  5. ((let/cc esc
  6. (done (+ 1 (let/cc k
  7. (esc k)))))
  8. 3)) ==>
  9. |#
  10. (print
  11. (prog (retval done arg1 func esc arg2 k arg3 arg4)
  12. (setq done (lambda(x) (setq retval x) (go DONE)))
  13. (setq arg1 3)
  14. (setq esc (lambda(x) (setq func x) (go ESC)))
  15. (setq arg3 1)
  16. (setq k (lambda(x) (setq arg4 x) (go K)))
  17. (setq arg4 (funcall esc k))
  18. (/ 0 0)
  19. K
  20. (setq arg2 (+ arg3 arg4))
  21. (setq func (funcall done arg2))
  22. (/ 0 0)
  23. ESC
  24. (setq retval (funcall func arg1))
  25. DONE
  26. (print retval) ; normally, (return retval) should be used
  27. ))
  28.  
  29. #| stackoverflow.com/questions/16529475/
  30. scheme-continuations-for-dummies/16531429#16531429
  31.  
  32. (prog (k retval)
  33. (setq k (lambda (x) ;; capture the current continuation:
  34. (setq retval x) ;; set! the return value
  35. (go EXIT))) ;; and jump to exit point
  36. (setq retval ;; get the value of the last expression,
  37. (progn ;; as usual, in the
  38. ;;;;;;;;;;;;;;;;
  39. (* 5 (funcall k 4)) ;; body of code
  40. ;;;;;;;;;;;;;;;;
  41. ))
  42. EXIT ;; the goto label
  43. (print retval))
  44. |#
Success #stdin #stdout 0s 10464KB
stdin
Standard input is empty
stdout
4 
NIL