3 ms·
So? I can easily write >> Y = ->(&x) { ->(f) { f[f] }[ ->(g) { x[ ->(*n) { g[g][*n] } ] } ] } >> fac = Y.call {|this| -> (n) { n > 0 ? n * this[n - 1
by stouset 13y ago
So? I can easily write
>> Y = ->(&x) { ->(f) { f[f] }[ ->(g) { x[ ->(*n) { g[g][*n] } ] } ] }
>> fac = Y.call {|this| -> (n) { n > 0 ? n * this[n - 1] : 1 } }
>> fac[5]
=> 120
You can argue that Ruby doesn't lend itself towards higher-order functional programming, but I asserting that Ruby isn't a function language isn't a tenable position.
- DanWaterworth 13y agoDo you deny that factorial, as I implemented it, is a function? Do you deny that I can't pass factorial into another function without creating an object to hold it? It doesn't matter what else is true. These facts alone mean that ruby's function's aren't first class.