From Esolang
Jump to: navigation, search

thaM is an esoteric programming language created by poiuy_qwert. The name thaM is actually just the word Math scrambled. The reason its name is made from Math is that it is designed to look like a mathematical equation. When you program in thaM, you should always try and make it valid math.


Every command in thaM is an operator from math, a number, or letter. Every number is pushed onto the main stack, every letter is a secondary stack, and the operators do the work.


There are 2 types of variables in thaM, the function variables and the data variables. The function variables can be the characters A-Z, currently there are only a few. The function variables have special built in functions. The current function variables are:

B - A special NOP that can be used with certain commands (explained more later). It can also be used to make your program look like correct math.
I - When you move a value from the I stack to another, it gets a character from input and pushes it on stack I before the copy is done.
O - When you move a value from a data variable onto the O stack, it is output as a character. If you push a number higher than 255, it just prints character 255. The same thing with lower than 1.
N - When you move a value from a data variable onto the N stack, it outputs the number.

The other type of variable is the data variables. They are infinite stacks that are referenced with characters a-z. The main stack is a data variable with no character to represent it.

For example:


This is the most simple cat program, it copies 1 character from input to output.


thaM only contains basic calculation operators:

+ - Add
- - Subtract
/ - Divide
* - Multiply

Each command takes the first number on the main stack, and performs its operation to it with the second number.

For example:


This would do 1+1 then output it as a number.


There are few commands in thaM, they are some of the advanced math operators that aren't used in thaM:

^ - Move the top value from the stack on the left of the ^, to the top of the stack on the right. If the same stack is on both sides, it duplicates the value. This also uses B to reference the main stack.
! - Pop the top value off the main stack.
, - Another NOP type command. This is used to separate numbers when you want to push 2 numbers in a row.
= - End the program.

For example:


This program will end with the user's input in stack a and b, with nothing on the main stack.

Flow Control

There are only 2 flow controls in thaM:

() - If the top value on the main stack is not 0, execute the code inside the brackets. If you have 2 sets of brackets one after the other, the second set is else.
[] - While the top value on the main stack is not 0, execute the code inside the brackets.

For example:


A more advanced cat program. This will continue to get a character input then output it, until a null character.


Comments are included in the language, but should not be used because they are too obviously not correct math. Comments are encased in |s.


Hello, World!

This program prints "Hello, World!"



This takes 1 character from input and outputs it:


This more complex one outputs its input till a null character:


Brainfuck Interpreter

Since this language is unimplemented, it is unknown if this program is correct. For a more readable and commented version of this code, visit the Talk Page.


External resources