From: Brian Candler Date: 2007-03-01T15:35:58+09:00 Subject: Re: Functional programming in Ruby On Thu, Mar 01, 2007 at 10:35:43AM +0900, James Edward Gray II wrote: > >proc { |*a| > > proc { |iter| iter.call(iter, *a) }.call( > > proc { |me, n, f| > > if n >= 1 > > f.call() > > me.call(me, n-1, f) > > end > > } > > ) > >}.call(3, proc { puts "hello again" } ) > > Wow, those melted my brain. > > I kept thinking I could peel off the outer layer off the factorial > one, but I didn't succeed. Wild stuff. Here's perhaps a cleaner version: proc { |n1, f1| proc { |func, *args| func.call(func, *args) }.call( proc { |me, n, f| if n >= 1 f.call() me.call(me, n-1, f) end }, n1, f1 ) }.call(3, proc { puts "hello again" } ) Line 2 encapsulates "a function which just calls the function+args you pass in, except passing the function itself as an extra argument" Cheers, Brian.