Last active
May 5, 2023 12:09
-
-
Save CodaFi/9926138 to your computer and use it in GitHub Desktop.
I know why the caged bird sings.
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 aviary.m -o aviary -framework Foundation -fobjc-arc && ./aviary | |
#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)); | |
} | |
/// Idiotbird Combinator; Alias for the I-Combinator. | |
typeof(id(^)(id))(*Idiotbird)() = I; | |
/// Kestral Combinator; Alias for the K-Combinator. | |
typeof(id(^)(id))(*Kestral)(id x) = K; | |
/// Starling Combinator; Alias for the S-Combinator. | |
typeof(typeof(id(^)(id))(^)(id))(*Starling)(typeof(id(^)(id))(^x)(id)) = S; | |
typeof(typeof(id(^)(id))(^)(id)) Bluebird(id(^bc)(id)) { | |
return lambda(id(^ab)(id))(lambda(id a)(bc(ab(a)))); | |
} | |
typeof(typeof(typeof(id(^)(id))(^)(id))(^)(typeof(id(^)(id, id)))) Blackbird(id(^cd)(id)) { | |
return lambda(id(^abc)(id, id))(lambda(id a)(lambda(id b)(cd(abc(a, b))))); | |
} | |
typeof(typeof(typeof(typeof(id(^)(typeof(id(^)(id))))(^)(typeof(id(^)(id))))(^)(typeof(id(^)(id))))(^)(id)) Bunting(id(^de)(id)) { | |
return lambda(id(^cd)(id))(lambda(id(^bc)(id))(lambda(id(^ab)(id))(lambda(id a)(de(cd(bc(ab(a)))))))); | |
} | |
typeof(typeof(typeof(id(^)(typeof(id(^)(id))))(^)(typeof(id(^)(id))))(^)(id)) Becard(id(^cd)(id)) { | |
return lambda(id(^bc)(id))(lambda(id(^ab)(id))(lambda(id a)(cd(bc(ab(a)))))); | |
} | |
typeof(typeof(id(^)(id))(^)(id)) Cardinal(id(^abc)(id, id)) { | |
return lambda(id a)(lambda(id b)(abc(b, a))); | |
} | |
typeof(typeof(typeof(id(^)(typeof(id(^)(id))))(^)(typeof(id(^)(id))))(^)(id)) Dove(id(^acd)(id, id)) { | |
return lambda(id a)(lambda(id(^bc)(id))(lambda(id b)(acd(a, bc(b))))); | |
} | |
typeof(typeof(typeof(typeof(id(^)(id))(^)(typeof(id(^)(id))))(^)(id))(^)(id)) Dickcissel(id(^abde)(id, id, id)) { | |
return lambda(id a)(lambda(id b)(lambda(id(^cd)(id))(lambda(id c)(abde(a, b, cd(c)))))); | |
} | |
typeof(typeof(typeof(typeof(id(^)(id))(^)(typeof(id(^)(id))))(^)(id))(^)(typeof(id(^)(id)))) Dovekie(id(^cde)(id, id)) { | |
return lambda(id(^ac)(id))(lambda(id a)(lambda(id(^bd)(id))(lambda(id b)(cde(ac(a), bd(b)))))); | |
} | |
typeof(typeof(typeof(typeof(id(^)(id))(^)(typeof(id(^)(id, id))))(^)(id))(^)(id)) Eagle(id(^ade)(id, id)) { | |
return lambda(id a)(lambda(id(^bcd)(id, id))(lambda(id b)(lambda(id c)(ade(a, bcd(b, c)))))); | |
} | |
/// #Murica #Freedom #GunsAndBeer #BeerAndGuns | |
typeof(typeof(typeof(typeof(typeof(typeof(id(^)(id))(^)(id))(^)(typeof(id(^)(id, id))))(^)(id))(^)(id))(^)(typeof(id(^)(id, id)))) BaldEagle(id(^efg)(id, id)) { | |
return lambda(id(^abe)(id, id))(lambda(id a)(lambda(id b)(lambda(id(^cdf)(id, id))(lambda(id c)(lambda(id d)(efg(abe(a, b), cdf(c, d)))))))); | |
} | |
typeof(typeof(typeof(id(^)(typeof(id(^)(id, id))))(^)(id))(^)(id)) Finch(id a) { | |
return lambda(id b)(lambda(id b)(lambda(id(^bac)(id, id))(bac(b, a)))); | |
} | |
/// Joy-Combinator | |
typeof(typeof(id(^)(id))(^)(id)) Jalt(id(^ac)(id)) { | |
return lambda(id a)(lambda(id b)(ac(a))); | |
} | |
typeof(id(^)(id)) Kite(id a) { | |
return lambda(id b)(b); | |
} | |
/// O-Combinator | |
typeof(id(^)(id)) Owl(id(^aba)(id(^)(id))) { | |
return lambda(id(^ab)(id))(aba(ab)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment