Y-combinator in Ruby with REAL λ!

Posted by flori Mon, 08 Oct 2007 17:02:00 GMT

#!/usr/bin/ruby -KU
# -*- coding: utf-8 -*- 

# Do ":imap <C-l> <C-k>l*" in vim

alias λ lambda

Y = λ{ |c|
  λ{ |f| f[f] }[
    λ{ |f| c[
      λ{ |x| f[f][x] } ] } ] }

Y[ λ{ |f| λ{ |n| n < 1 ? 1 : n * f[n-1] } } ][10] # => 3628800

And they say reading ruby-core doesn't pay off! :-)

Tags , ,  | no comments

Comments

Comments are disabled