Settings

Theme

Continuations by example: Exceptions, time-traveling search, threads, and more

matt.might.net

151 points by alschwalm 5 years ago · 18 comments

Reader

verytrivial 5 years ago

I always start Matt Might articles thinking "Okay, THIS is the one I'm going to understand all the way to the very end without unlearning what I just read, else I die," and alas, I have again died.

emmanueloga_ 5 years ago

I was actually relieved when I found this article [1] which argues against call/cc as a core language feature. Alas, I think the argument does not dismiss _delimited continuations_, so now my burden has shifted from mastering call/cc to mastering shift/reset :-/ [2].

1: http://okmij.org/ftp/continuations/against-callcc.html

2: https://en.wikipedia.org/wiki/Delimited_continuation

jolmg 5 years 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?

  • gus_massa 5 years ago

    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.
  • kazinator 5 years ago

    Continuations can be implicitly used. If you have a language that is compiled using transformation to CPS. Then continuations are everywhere under the hood.

  • a1369209993 5 years ago

    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
Google234 5 years ago

Wow, imagine writing in such an unreadable language

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection