I present to you a little language I made (with similarities to the λ-calculus) that I named "λ". The interpreter was whipped up in 63 lines of (un-minified) JS, so yes it's tiny. To give a quick feel for the language, here's a sample program that prints "Three times" three times to the console:
λ λ || ID λλ λ y λ y λ y λλ || Church numeral three λ 3λ "Three times" 1λ || Main
You can probably see why I named it "λ" — rather than all the nice clarifying details of standard lambda calculus, it primarily uses only the character "λ" and "y" (which looks like an upside-down λ). So, without further ado let me explain what the above program does:
- We define a function that takes one argument (count the number of λ's) and returns it (everything after the first string of λ's is the body of the function). This is the identity function, it's good to define this in a program just to have it as a dummy value.
||indicates a comment, everything after it on that line is ignored.
- We define another function, which takes two arguments. It is defined as Church numeral three — namely, it takes a function and another function and applies the first function to the second three times. The
yis akin to Haskell's
λ λ λ λλis equivalent to
((λ λ) λ) λλ, while
λ y λ y λ y λλis equivalent to
λ (λ (λ λλ)))
- We create the entry point of the program. The entry point takes one argument, which will be the identity function (this has nothing to do with the fact that we defined it first here, the entry point will always get passed the identity function regardless of the rest of the program). The body of the entry point is equivalent to
(λ3 "Three times") λ1, which calls the function defined on line 3 (Church numeral 3) with the string function "Three times", and then calls the result of that with the function defined on line 1 (the ID function).
I say "string function" for a reason. Strings are merely here for debugging purposes — they are not values, the only value is a function (like the true λ-calculus). A string is just an instance of the identity function, with the side-effect of printing the string value to the console. So, if I call
"Three times" with some value
x, then it will print "Three times" to the console and return the value
x. This means that our entry point will call "Three times" three times, so "Three times" will get printed three times.
Confusing yet? If so, great — this is an esoteric language, it's not supposed to make sense :D
Suggestions welcome! If anyone manages to make something useful with this, I will be surprised!