(display
(call/cc (lambda (cc)
(display "I got here.\n")
(cc "This string was passed to the continuation.\n")
(display "But not here.\n"))))
Edit: Tried playing around with mit-scheme, but it doesn't work with the ctrl-v'ing the examples. Chezscheme does work.Changing it to the following should work:
(let ((start #f))
(if (not start)
(call/cc (lambda (cc)
(set! start cc))))
(display "Going to invoke (start)\n")
(start #f))
[0] https://www.gnu.org/software/mit-scheme/documentation/stable...Full disclosure: I'm the one who built / owns the first project.
Has anyone used continuations in a serious/non-academic way?
#lang racket
; implement sqrt in a very inefficient way
(let/ec exit
(for ([i 10])
(when (= (* i i) 49)
(exit i)))
"not found :(")
;==> 7
There are more idiomatic and easy ways to write this, but when you have to many nested and not nested for's, sometimes it is useful to have a magical exit-everything-now. func a0 a1 = callcc \return:
# ...
callcc (again =)
# ...
x ?? return y
again again