Is there any way to get a hold of the current block? I’ve been playing
around with recursive enumerations and it occurs to me that the most
flexible technique would simply be to reuse the currently running
block.
For example, where this would be the current block:
On Fri, Aug 27, 2010 at 10:42 AM, Intransition [email protected]
wrote:
 #=> {“a”=>“1”, “b”=>{“c”=>“3”}}
That’s called the Y-combinator, something i wish could be added to
core, but would be afraid of the many nay-sayers who are already
confused by the current number of ways of creating blocks
def y(*args, &block)
y = lambda{|*args| block.(*args, &y) }
end
p y{|n, acc, &b|
n < 2 ? acc : b.(n-1, n * acc)
}.(5, 1)
Is there any way to get a hold of the current block? I’ve been playing
around with recursive enumerations and it occurs to me that the most
flexible technique would simply be to reuse the currently running
block.
Limited, and pure evil:
lambda { |x| p x += 1; redo }[0]
Infinitely increments. redo lets you restart the current block, but
you must manipulate the original args instead of passing 'em. Don’t do
this.