[ create a new paste ] login | about

Link: http://codepad.org/C3kVMzVi    [ raw code | output | fork ]

DigitalGhost - C++, pasted on Aug 24:
#include <iostream>

#define LET(var) [&] { var IN
#define IN(body) return body; }()

#define LAMBDA(def) [&] { LAMBDA_WHERE(LAMBDA_WHERE_I def) return LAMBDA_BODY def )); }()
#define LAMBDA_WHERE_I(body) LAMBDA_WHERE_II
#define LAMBDA_WHERE_II(where) NIL where
#define LAMBDA_WHERE(where) LAMBDA_WHERE_III(where)
#define LAMBDA_WHERE_III(where) LAMBDA_WHERE_IV_ ## where
#define LAMBDA_WHERE_IV_LAMBDA_WHERE_II
#define LAMBDA_WHERE_IV_NIL

#define LAMBDA_BODY(body) body LAMBDA_BODY_I((
#define LAMBDA_BODY_I(par)

#define TO_STR(a) TO_STR_I(a)
#define TO_STR_I(a) TO_STR_II(a)
#define TO_STR_II(a) #a

int main() {
    using namespace std;
    // let風
    cout << TO_STR(LET (int x = f(1, 2, 3);) (_1 + x)) << '\n';

    // where風
    cout << TO_STR(LAMBDA((_1 + x)(int x = f(1, 2, 3);))) << '\n';
    cout << TO_STR(LAMBDA((_1 + 1))) << '\n';
}


Output:
1
2
3
[&] { int x = f(1, 2, 3); return _1 + x; }()
[&] { int x = f(1, 2, 3); return _1 + x ; }()
[&] { return _1 + 1 ; }()


Create a new paste based on this one


Comments: