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 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).

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