Return prematurely from function in Racket

How do I return from a function before reaching the last form in standard Racket? This can be useful to avoid a different level of indentation and nesting.

Common Lisp has return , a specialized form of return. Any equivalent in Racket, at least for refund?

+7
function return racket
source share
1 answer

Use let/ec to create a continuation of the continuation.

Example:

 (let/ec return (for ([x 10000]) (when (= x 100) (return x)))) 

Using let / ec is cheaper than using call / cc, which creates a full sequel.

+8
source share

All Articles