Hacker News new | ask | show | jobs
by jolmg 2170 days ago
I think I've found a good use for continuations in a parser combinator library I'm writing, though I haven't gotten around to working on the corresponding feature yet.

Has anyone used continuations in a serious/non-academic way?

3 comments

I used to implement an equivalent of exit or return statement, like in this example.

  #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.
Continuations can be implicitly used. If you have a language that is compiled using transformation to CPS. Then continuations are everywhere under the hood.
You could dispute "serious", but I've used it in a not!lisp for various control flow purposes.

  func a0 a1 = callcc \return:
    # ...
    callcc (again =)
      # ...
      x ?? return y
    again again