KLC LANG

A toy programming language for daily math.

KLC (pronounced `calc`) is a simple toy programming language for basic math, created for studying programming language design and development.

Why?

KLC was created primarily for fun and learning design and development of programming languages, and secondarily for daily math - calculus that requires conversions and a bit more than what calculator apps usually provides.

Language

In KLC there are only numbers and functions. You can perform all common operations upon numbers:

normal(x, mean, std) = 1/(std*sqrt(2pi)) * exp(-.5((x-mean)/std)^2)
a = normal(0, 0, 1)

Operators

KLC supports a variety of operators for performing calculations and comparisons. Booleans are represented as numbers, where 0 is false and any non-zero value is true.

-- Arithmetic Operators:
5+10 -- add
5-10 -- sub
5*10 -- mul
5/10 -- div
5^10 -- pow
5%10 -- mod

-- Relational Operators:
5 == 10 -- eq
5 != 10 -- neq
5 < 10  -- lt
5 <= 10 -- lte
5 > 10  -- gt
5 >= 10 -- gte

-- Logical Operators:
!1 -- not
0 and 1
0 or 1

All arithmetic operators can also be used in the assignments, such as a += 1.

Metrics System

KLC supports the metric system, allowing you to write expressions using metric units. This feature makes it easier to perform calculations involving units of measurement. For example:

1m to cm -- 100
36deg to rad -- 2062.648062
10hour to sec -- 36000
1831936KB to MB -- 1789
1831936KB to GB -- 1.747070

Supported units:

Functions

Functions uses pattern matching to select which version will be used, depending on the arguments:

-- Factorial
factorial(0) = 1
factorial(x) = x * factorial(-1)

-- Fibonacci
fib(0) = 0
fib(1) = 1
fib(x) = fib(x-1) + fib(x-2)

factorial(5) -- 120
fib(5) -- 5

More Information

For more information, including how to install, how to use in terminal, and source code, please visit the github page:

https://github.com/renatopp/klclang