Skip to content

Instantly share code, notes, and snippets.

@FreeBirdLjj
FreeBirdLjj / repl.cc
Created March 30, 2023 14:58
A useful macro to simulate a REPL in C++.
#include <iostream>
#define REPL(expr) std::cout << "> " << #expr << std::endl << (expr) << std::endl
int main()
{
int a = 1, b = 2;
REPL(a + b);
// print out:
// > a + b
@FreeBirdLjj
FreeBirdLjj / y-combinator.rkt
Created September 19, 2014 02:58
A racket version of y-combinator.
(define (y-combinator fn)
((lambda (func)
(func func))
(lambda (f)
(fn (lambda args
(apply (f f) args))))))
@FreeBirdLjj
FreeBirdLjj / switch.lua
Last active December 27, 2023 00:22
A way to write switch-case statements in lua.
print "Hello, switch"
-- Suppose we want to write the equivalent lua code of the following c code:
-- switch (a) {
-- case 1:
-- printf("Case 1.\n");
-- break;
-- case 2:
-- printf("Case 2.\n");
-- break;