Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How the christ does the Y Combinator work?

Name: Anonymous 2010-10-20 22:39

Fuck, I've been rereading http://mvanier.livejournal.com/2897.html for the past several hours and it might as well be written in Esperanto. Am I just not cut out for EXPERT PROGRAMMING

Name: Anonymous 2010-10-23 1:56

Wait a second...

So Y is just a fancy way to write ff=Y(f); ff(arg) (forgive my C roots) instead of f(f,arg)?

Wow. And I thought is was something serious.

Name: Anonymous 2010-10-23 7:22

>>17
It's a fancy way to write ff=Y(f); ff(arg) instead of f(f(f(f(f(f(f(f(f(f(f(f(f(f(...ff...))))))))))))), arg).

Name: Anonymous 2010-10-23 8:26

>>20
Uh..

Here, check this perl code out. $fact contains an anonymous recursive function not using anything outside of its scope. $y_fact is the same thing only with Y.

my $fact=sub{
    my($func,$arg)=@_;
   
    return 1 if $arg==0;
   
    return $arg*$func->($func,$arg-1)
};

my $y=sub{
    my($func)=@_;
   
    return sub{
        return $func->($func,@_);
    }
};

print $fact->($fact,5),"\n"; # prints 120

my $y_fact=$y->($fact);
print $y_fact->(5),"\n";     # prints 120, too. So much for Y combinator...


The only difference from paper someone linked to is that my function accepts two arguments at once while their accepts one and returns a function that accepts another one (but the dead dog taught us this is the same thing).

Name: Anonymous 2010-10-23 11:37

>>23
Practically though, this is only syntactic sugar. Any function that can be written your way can also be written my way. The only difference that in each call to my function I have to specify it as first argument. Y is a wrapper that does it for me by putting that function I otherwise would have to specify myself into environment of function it returns. If you're >>20 I want you to apologize for the nonsense you wrote without thinking.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List