News for hackers. Stuff that matters.
Re:Y Combinator in Python by silentbicycle on Thursday October 30, 2008 @06:19PM (#349318)
Of course, if you actually use this you can smash the stack -- Python doesn't currently have any kind of tail call optimization. (That factorial function isn't tail-recursive anyway, though.)

It doesn't look like Ruby has tail-call optimization, either. Lua does...what other primarily-scripting (i.e., not Scheme or Haskell) languages do?

Re:Y Combinator in Python by burke on Thursday October 30, 2008 @05:57PM (#349293)

    # Ruby 1.8.7
    def Y
      lambda { |f| f.call(f) }.call(
        lambda do |g|
          yield(lambda { |*n| g.call(g).call(*n) })
        end)
    end
    Y { |this| lambda { |n| n == 0 ? 1 : n * this.call(n - 1) } }.call(5)
    #=> 120
Re:Y Combinator in Python by pavelludiq on Thursday October 30, 2008 @06:41PM (#349343)
The Y combinator is just like python decorators, or generators, you just HAVE to blog about them, or you're not C001!
Re:Y Combinator in Python by markessien on Thursday October 30, 2008 @05:45PM (#349278)
This must be about the 6th different 'Y Combinator in X' I have seen on this site.
Re:Y Combinator in Python by daragh on Thursday October 30, 2008 @08:50PM (#349466)
That's a pretty solid butchering of the design of daringfireball.net
Re:Y Combinator in Python by kingkongrevenge on Thursday October 30, 2008 @05:24PM (#349246)
Perl6 ftw:

my $factorial = sub (Int $x) { $x < 2 ?? 1 !! $x * &?ROUTINE($x - 1); }