RatLang is an open source programming language that wants to replace your calculator.

Examples

Hello World

rat> \"Hello World!"
Hello World!

Print anything by putting a backslash in front.

Basic arithmetic

rat> 3.0/20.0
0.15

Simple math works like you’d expect. This can be simplified to:

rat> 3./20.
0.15

And simplified even more to:

rat> 03/20
0.15

Implicit decimal point

One of the biggest differences between RatLang and other languages is the implicit decimal point. If you type a natural number without a decimal point like 35, it will be treated as 0.35 instead. This lets you write percentages easier:

rat> 3.50*80*70*1.08
2.11680

Alternate operators

Since parentheses are hard and clumsy to type, a second set of arithmetic operators with higher precedence has been introduced in addition to the regular operators.

rat> 3p4/1p6      # Equivalent to (0.3*0.4)/(0.1*0.6)
2.0
rat> 3s41*2s1     # Equivalent to (0.3 + 0.41) * (0.2 + 0.1)
0.213

The two lines of code above should be read as .3 product .4, divided by .1 product .6 and .3 sum .41, multiplied by .2 sum .1.

Operator precedence is defined as follows:

OperationExample
Function callsSUM(3, 5) → 0.8
Negation-2.0 → -2.0
Base-10 exponentiation1.6e-3.0 → 0.0016
To the power of1.6 * 10.0t-3.0 → 0.0016
Remainder11r9 → 0.11
Product
Quotient
2.0p3.0 → 6.0
3.0q4.0 → 0.75
Sum
Difference
7s9 → 1.6
8d3 → 0.5
Power1.6 * 10.0^-3.0 → 0.0016
Mod11%9 → 0.11
Times
Slash
2.0*3.0 → 6.0
3.0/4.0 → 0.75
Plus
Minus
7+9 → 1.6
8-3 → 0.5

Parentheses can be used to group expressions and override this order of operations. However, you will find that parentheses are rarely necessary in RatLang, as you get more comfortable with the alternate operators.

Variables

rat> lA = 4       # "Let" A equal 0.4
0.4
rat> \A
0.4

Variable names consist of one or more uppercase letters or underscores. Lowercase letters are not allowed in variable names since they're used as operators.

Functions

rat> lA = f(X){X + 3}
(function value)
rat> \A(3)
0.6

The f operator is used to define lambda expressions. Functions in RatLang are purely functional and can have no side effects. They consist of an argument list and a return expression, which can be another function. All functions are anonymous and can be assigned to variables like normal values.

Manual

A complete user's manual for RatLang is coming soon.

Download

You can download and compile the source code for RatLang yourself from GitHub. You will need the following tools before you begin:

Grab the latest version of the source code via git or HTTP:

# Via git
user@console $ git clone git@github.com:rogerhub/ratlang.git

# Via HTTP
user@console $ wget "https://github.com/rogerhub/ratlang/archive/master.zip"
user@console $ unzip master.zip

Then, run the ./autogen.sh script, configure the installation with ./configure, and make && sudo make install.

You can give a prefix to ./configure and make install to install RatLang without superuser privileges. This is recommended, since RatLang is experimental alpha software.