Skip to content

Instantly share code, notes, and snippets.

@CodaFi
Last active August 29, 2015 13:57
Show Gist options
  • Save CodaFi/9882917 to your computer and use it in GitHub Desktop.
Save CodaFi/9882917 to your computer and use it in GitHub Desktop.
// 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));
}
@winocm
Copy link

winocm commented Mar 31, 2014

help

help

HELP ME BEFORE IT'S TOO LATE

@robrix
Copy link

robrix commented Mar 31, 2014

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