irb:001:0> def y(&f)
irb:002:1> lambda {|x| x[x]}[
irb:003:2* lambda {|yf|
irb:004:3* lambda {|*args| f[yf[yf]][*args]}
irb:005:3> }
irb:006:2> ]
irb:007:1> end
irb:008:0> fac = lambda {|n|
irb:009:1* y {|r|
irb:010:2* lambda {|x,acc|
irb:011:3* x == 0 ? acc : r[x-1, x*acc]
irb:012:3> }
irb:013:2> }[n, 1]
irb:014:1> }
irb:015:0> fac[5]
=> 120
irb:002:1> lambda {|x| x[x]}[
irb:003:2* lambda {|yf|
irb:004:3* lambda {|*args| f[yf[yf]][*args]}
irb:005:3> }
irb:006:2> ]
irb:007:1> end
irb:008:0> fac = lambda {|n|
irb:009:1* y {|r|
irb:010:2* lambda {|x,acc|
irb:011:3* x == 0 ? acc : r[x-1, x*acc]
irb:012:3> }
irb:013:2> }[n, 1]
irb:014:1> }
irb:015:0> fac[5]
=> 120
2 comments:
I take it that you are done with "Three Brothers" then?
Not exactly... it's uptime is so shameful that I felt like I should have a decoupled blog. When I get it up again, I'll probably use Three Brothers for more technical/nerdly posts. I'll work some RSS feed merging magic to get both blogs up through Feedburner, and everyone will win!
Post a Comment