Hacker News new | ask | show | jobs
by gus_massa 2169 days 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.