Last active
August 29, 2015 13:57
-
-
Save CodaFi/9882917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cc lambda.m -o lambda -framework Foundation -fobjc-arc && ./lambda | |
#import <Foundation/Foundation.h> | |
// use it like lambda(…args…)(…return value…) | |
#define lambda(...) \ | |
^ (__VA_ARGS__) _lambda_body | |
#define _lambda_body(...) \ | |
{ return __VA_ARGS__; } | |
/// I-Combinator | |
typeof(id(^)(id)) I() { | |
return lambda(id x)(x); | |
} | |
/// K-Combinator | |
typeof(id(^)(id)) K(id x) { | |
return lambda(id y)(x); | |
} | |
/// S-Combinator | |
typeof(typeof(id(^)(id))(^)(id)) S(typeof(id(^)(id))(^x)(id)) { | |
return lambda(id(^y)(id))(lambda(id z)(x(z)(y(z)))); | |
} | |
/// Y-Combinator | |
typeof(typeof(id(^)(id))(^)(id)) Y(id(^z)(id)) { | |
return lambda(typeof(id(^)(id))(^f)(id))(lambda(id(^x)(id))((id(^)(id))f(x(x))))(lambda(id(^t)(id))(z)); | |
} |
Grumble, Grumble, Grumble; something about currying.
I am very scared, but I'll go along with whatever is happening here.
Ah, I see someone else figured out the nuclear launch code generator.
Step lightly in the Church of Turing.
help
help
HELP ME BEFORE IT'S TOO LATE
And I’ll look down and whisper, “No.”
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THIS IS LAMBDA CALCULUS