3 ms·
Nice demonstration of preprocessor powers. Compiling this file (cd examples; cmake .; make) took just under half a minute. Adding an exponentiation test #
by tromp 5y ago
Nice demonstration of preprocessor powers.
Compiling this file (cd examples; cmake .; make) took just under half a minute.
Adding an exponentiation test
#define POW LAM(LAM(APPL(VAR(1), VAR(2))))
#define TWO_TO_THE_FOUR APPL(APPL(POW, TWO), FOUR)
#define FOUR_SQUARED APPL(APPL(POW, FOUR), TWO)
ASSERT_REDUCES_TO(TWO_TO_THE_FOUR, FOUR_SQUARED);
nearly doubles the time.
Adding some Pythagoras
#define FIVE APPL(SUCC, FOUR)
#define SQUARE LAM(APPL(APPL(MUL, VAR(1)), VAR(1)))
ASSERT_REDUCES_TO(APPL(APPL(ADD, APPL(SQUARE, THREE)), APPL(SQUARE, FOUR)), APPL(SQUARE, FIVE));
bumps the time to 3 minutes.
Currying works fine too; one can simplify the definitions
#define IF LAM(LAM(LAM(APPL(APPL(VAR(3), VAR(2)), VAR(1)))))
#define MUL LAM(LAM(LAM(LAM(APPL(APPL(VAR(4), APPL(VAR(3), VAR(2))), VAR(1))))))
to
#define I LAM(VAR(1))
#define IF I
#define MUL LAM(LAM(LAM(APPL(VAR(3), APPL(VAR(2), VAR(1))))))
I tried to see at what point things break; perhaps at this point
#define SEVENTEEN APPL(SUCC, APPL(SQUARE, FOUR))
#define FOUR_CUBED APPL(APPL(POW, FOUR), THREE)
#define THREE_TO_THE_FOUR APPL(APPL(POW, THREE), FOUR)
ASSERT_REDUCES_TO(APPL(APPL(ADD, FOUR_CUBED), SEVENTEEN), THREE_TO_THE_FOUR);
that yields an error: pasting formed ';_IMPL', an invalid preprocessing token
I like the choice of False for Nil, which I also made in my Binary Lambda Calculus [1]
[1] https://tromp.github.io/cl/Binary_lambda_calculus.html#Delimited_versus_undelimited https://tromp.github.io/cl/Binary_lambda_calculus.html#Delim...
- Hirrolot 5y agoYeah, the macro-based lambda calculus is pretty slow, since it's essentially an interpreter upon interpreter upon interpreter! The first one is preprocessor, which executes Metalang99, which executes the final calculus.
- lisper 5y agoFor the benefit of those like me who hadn't heard of Metalang99: https://news.ycombinator.com/item?id=27919448 https://news.ycombinator.com/item?id=27919448
- ngcc_hk 5y agoIf this is example, I am not sure I want to learn. Lisp whilst is a high learning curve at least it is not verbose by nature (many writing is but not the language). This is hard to follow. More examples needed.