fork download
  1. def combinator &b
  2. lambda do |f|
  3. lambda{|x|lambda{|y| f[x[x]] [y]}}[
  4. lambda{|x|lambda{|y| f[x[x]] [y]}}]
  5. end[ lambda{|f|lambda{|n| b[n , &f] }}]
  6. end
  7.  
  8. a = combinator do | n , &f |
  9. if n == 0
  10. 1
  11. else
  12. n * f.call(n-1)
  13. end
  14. end
  15.  
  16. p a.call 7
  17.  
  18.  
  19.  
  20. def recursion &b
  21. f = ->*n{ b[ *n , &f ] }
  22. end
  23.  
  24. a = recursion do |n , &rec|
  25. if n == 0
  26. 1
  27. else
  28. n * rec.call(n-1)
  29. end
  30. end
  31. p a.call 7
Success #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
5040
5040