kalc
Introduction
kalc is a small functional programming language that (gasp) borrows a lot of its syntax from the Excel formula language.
ikalc
kalc comes with its own repl, known as ikalc. It evaluates when you press return.
Syntax
kalc is a tiny language, and it has very little syntax. It does support functions, variable assignment, and arithmetic.
Arithmetic
1 + 1 / (10 * 100) - 3 + 3 - (3 - 2)
1 > 1
SUM(1, 2, 3, 4, 5)
Arithmetic is standard infix with nesting via parenthesis.
Logical operations
1 > 2 ? 1 : 3 # Ternary
(1 || 2) > 3
1 > 2 or 3 < 2 # false
OR(1 > 2, 3 < 2, 8 == 8) # true
Variable assignment
a = 1
b = 2
d = a + b
Creating functions
DEFINE FOO(a, b) {
a + b
}
There are a few examples of functions in lib/stdlib.kalc
Loops
There are no looping mechanisms to speak of, but recursion works well.
DEFINE SAMPLE_LOOP(a) {
PUTS(a)
IF(a == 1, 1, SAMPLE_LOOP(a - 1))
}
More inside
Not everything is documented yet. As you can see, it is a mix of a lot of different ideas. The goal is to have an excel-like language that is somewhat functional.
Contributing
Fork on GitHub and after you’ve committed tested patches, send a pull request.