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