4 ms·
Anonymous functions return from themselves, whereas a block is a special kind of closure that returns from the caller. It's probably less important in Clojure s
by orthoxerox 3y ago
Anonymous functions return from themselves, whereas a block is a special kind of closure that returns from the caller. It's probably less important in Clojure since it is more functional and doesn't use explicit control flow much.
- aeonik 3y agoThis is the part that fascinates me about Code Blocks so much. Is it like an extra break or return statement at the end of it that bails out of the context of whatever method it's running in? Or does it actually return back to the original all site after nested passes of the Code Block?
- orthoxerox 3y agoI am not a rubyist, but a block (which I think is properly called a proc) is different from a regular lambda in that its control flow statements are lexically scoped to the method it is defined in. A return statement in a lambda returns from a lambda (and always succeeds), a return statement in a block returns from the method the block was defined in (and fails with a LocalJumpError if the call frame is no longer on the call stack). I think Kotlin has a similar distinction between lambda expressions that return from the definer (and it ensures that you're passing them to an inline function that won't save the closures for later) and anonymous functions that return from themselves.