Skip to content
Compiler for small-tiny-mini language to play with lambdas
HTML JavaScript Nearley
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Better runner Dec 7, 2018


Compiler for small-tiny-mini language to play with lambdas

For a code like this:

let next = n.f.x.(f ((n f) x))
let sum = a.b.((a next) b)
let mul = a.b.f.(a (b f))
let prev = n.f.x.(((n g.h.(h (g f))) u.x) u.u)

let zero = f.x.x
let one = f.x.(f x)
let two = (next one)
let three = (next two)
let four = (next three)

(num (prev three))
(num ((mul three) four))
(num ((sum four) three))

It will compile a js like this:

const next = n=> f=> x=> f(n(f)(x));
const sum = a=> b=> a(next)(b);
const mul = a=> b=> f=> a(b(f));
const prev = n=> f=> x=> n(g=> h=> h(g(f)))(u=> x)(u=> u);
const zero = f=> x=> x;
const one = f=> x=> f(x);
const two = next(one);
const three = next(two);
const four = next(three);

And will output something like this:



Clone the repo, run npm i.

Then you can use ./lambdas executable if you're lucky to have *nix system. Otherwise run it as node ..

Then try it out on the Church encoding sample code:

./lambdas examples/church.l


Check out railroad diagrams for the grammar.


Lambdas are functions. They can accept only one argument and must return something.

Id lambda:


Value lambda:



Application is function invocation with an argument. Only one argument.

The following will output 123, as log is a predefined function for printing stuff.

(log 123)

Variable binding

You can bind expressions evaluation results to the names. Values given to those names are immutable.

let num = 123
let fun = a.a
let call = (log 123)

Missing stuff

  • Commments (But they're planned, kinda)
  • Strings
  • Math operators, such as + - / * ^, etc.
  • Objects
  • Arrays
  • Tuples
  • Lists
  • More than one argument for the function
  • 0 arguments for the function
  • Pretty much everything else

We don't need all above, really

Things it has built-in

  • _ variable, it evaluates to undefined eventually
  • log function
  • num function that accepts function as argument and will pass function to that function to count how many times it will be invoked, in the end it will invoke what the argument function returned, so it should be a function.


To the awesome parser generator Nearley.js

You can’t perform that action at this time.