Created
March 31, 2014 02:51
-
-
Save robrix/9884336 to your computer and use it in GitHub Desktop.
Not quite as good as I’d hoped, but you can do some fun things with __typeof__.
This file contains hidden or 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 autotes.m -o autotes -framework Foundation -fobjc-arc && ./autotes | |
| #import <Foundation/Foundation.h> | |
| // use it like lambda(…args…)(…return value…) | |
| #define lambda(...) \ | |
| ^(__VA_ARGS__) _lambda_body | |
| #define _lambda_body(...) \ | |
| { return __VA_ARGS__; } | |
| #define autotes(v, ...) \ | |
| __typeof__(__VA_ARGS__) v = (__VA_ARGS__) | |
| int main(int argc, const char *argv[]) { | |
| @autoreleasepool { | |
| // riffing off @CodaFi’s combinatorial riff off lambda()() | |
| autotes(I, lambda(id x)(x)); | |
| typedef __typeof__(I) I_t; | |
| autotes(K, lambda(id x)(lambda(id y)(x))); | |
| autotes(S, lambda(I_t(^x)(I_t))(lambda(I_t(^y)(I_t))(lambda(id z)(x(z)(y(z)))))); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment