Skip to content

Instantly share code, notes, and snippets.

@manuel
Created March 31, 2014 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuel/9896175 to your computer and use it in GitHub Desktop.
Save manuel/9896175 to your computer and use it in GitHub Desktop.
;; Causes stack overflow:
(def p 'p)
(def (spawn-thread)
(push-prompt p
(loop
(sleep))))
(def (sleep)
(take-subcont p k
(def (callback . #ignore)
(push-prompt p
(push-subcont k)))
($setTimeout (js-callback callback) 0)))
(spawn-thread)
;; Replace (push-prompt p (push-subcont k)) with (push-prompt-subcont p k) -> constant stack space
;; push-prompt-subcont is Oleg's push-delim-subcont
(def p 'p)
(def (spawn-thread)
(push-prompt p
(loop
(sleep))))
(def (sleep)
(take-subcont p k
(def (callback . #ignore)
(push-prompt-subcont p k))
($setTimeout (js-callback callback) 0)))
(spawn-thread)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment