Skip to content

Instantly share code, notes, and snippets.

@CodaFi
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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));
}
@robrix
Copy link

robrix commented Mar 31, 2014

Unfortunately, actually using these would require some notion of partial function application, which we don't get with blocks

THIS IS LAMBDA CALCULUS

lambda(id x)(lambda(id y)(x))

@CodaFi
Copy link
Author

CodaFi commented Mar 31, 2014

Grumble, Grumble, Grumble; something about currying.

@winocm
Copy link

winocm commented Mar 31, 2014

I am very scared, but I'll go along with whatever is happening here.

@JFKingsley
Copy link

Ah, I see someone else figured out the nuclear launch code generator.

@robrix
Copy link

robrix commented Mar 31, 2014

Step lightly in the Church of Turing.

@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