Skip to content

Comment on Continuations by example: Exceptions, time-traveling search, threads, and moreparent

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.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.