CLAG
Paradigm(s) | imperative |
---|---|
Designed by | QuarticSushi |
Appeared in | 2022 |
Memory system | Cell-based |
Dimensions | one-dimensional |
Computational class | Turing complete |
Major implementations | CLAGy |
Influenced by | brainfuck |
File extension(s) | .clag |
CLAG is yet another brainfuck derivative language. It has been created to be particularly difficult to read, as every command is made from nearly identical Unicode characters, being the Cyrillic "о", the Latin "o", the Armenian "օ", and the Greek "ο", hence the name CLAG.
Language overview
CLAG operates on an infinite array of cells, each initially set to 0. A cell value cannot be negative, but, in theory, has no upper bound. There is a pointer, initially set at the first cell. All numbers are written in base 8, and are either added to or subtracted from the current cell, based on the preceding оօ or оο.
Commands
Brainfuck Command | CLAG Command | CLAG Unicode | Description |
---|---|---|---|
> |
оо |
U+043E U+043E | Increment pointer |
< |
оo |
U+043E U+006F | Decrement pointer |
+ |
оօ |
U+043E U+0585 | Add following value |
- |
оο |
U+043E U+03BF | Subtract following value |
. |
oо |
U+006F U+043E | Output character |
, |
oo |
U+006F U+006F | Get input |
[ |
oօ |
U+006F U+0585 | Go past matching ] if 0 |
] |
oο |
U+006F U+03BF | Go to matching [ |
օо |
U+0585 U+043E | 0 | |
օo |
U+0585 U+006F | 1 | |
օօ |
U+0585 U+0585 | 2 | |
օο |
U+0585 U+03BF | 3 | |
οо |
U+03BF U+043E | 4 | |
οo |
U+03BF U+006F | 5 | |
οօ |
U+03BF U+0585 | 6 | |
οο |
U+03BF U+03BF | 7 |
All other characters are regarded as comments. this does create the additional inconvenience, that all comments cannot contain the letter o, as the o will be read as a command, with the next valid character, causing unpredictable behavior.
I/O
Input
CLAG takes a string as input, and sets the current cell to the sum of Unicode values of the characters in the string.
For example, if "hello" was provided as an input, the current cell would be set to 104 + 101 + 108 + 108 + 111 = 532.
Output
When outputting a character, CLAG takes the current cell value, and outputs the corresponding Unicode Character.
For example, if the current cell value was 1383, the character output would be է
Differences from brainfuck
Integers
The main functional difference between CLAG and brainfuck is the ability to express integers using a positional notation. in brainfuck, the shortest way to express the number 42 is:
++++++[>+++++++<-]> (19 commands)
While in CLAG, it is:
оօ οoօօ (3 c0mmands)
Implementations
Brainfuck has many different styles of implementation, with differing tape lengths, cell sizes, wrapping rules, and so on. There is only one official way to implement CLAG. CLAG runs on an infinite tape, each cell has a lower bound of 0, and no upper bound. This eliminates the ambiguity sometimes caused by wrapping.
Algorithms
Simple algorithms commonly used when writing CLAG programs. Explanations in a brainfuck like syntax are shown beside each line.
Set cell to 0
Sets the current cell to zero.
oօ оοօo oο [ -1 ]
Copy cell
Copies the value of the current cell to the cell to the right, while preserving the value of the original cell.
oօ оοօo оо оօօo оо оօօo оoоo oο [ -1 > +1 > +1 << ] оооо oօ оοօo оoоo оօօo оооо oο >> [ -1 << +1 >> ]
Examples
Example programs written in CLAG. Explanations in a brainfuck like syntax are shown beside each line.
Hello, World!
This program prints out the words "Hello World!":
оօ օoօoօо oо оо + 72 . > (Displays 'H') оօ օoοоοo oо оо + 101 . > (Displays 'e') оօ օoοoοо oо оо + 108 . > (Displays 'l') оօ օoοoοо oо оо + 108 . > (Displays 'l') оօ օoοoοο oо оо + 111 . > (Displays the letter after n) оօ οоօо oо оо + 32 . > (Displays ' ') оօ օoօօοο oо оо + 87 . > (Displays 'W') оօ օoοoοο oо оо + 111 . > (Displays the letter after n) оօ օoοօօօ oо оо + 114 . > (Displays 'r') оօ օoοoοо oо оо + 108 . > (Displays 'l') оօ օoοоοо oо оо + 100 . > (Displays 'd') оօ οоօo oо + 33 . (Displays '!')
The program in minimized form:
оօօoօoօоoооооօօoοоοooооооօօoοoοоoооооօօo οoοоoооооօօoοoοοoооооօοоօоoооооօօoօօοοoо оооօօoοoοοoооооօօoοօօօoооооօօoοoοоoооооօ օoοоοоoооооօοоօooо
Cat program
This program writes the input character directly to the output.
oo oօoо oօоοօooο oooο , [. [-1] ,]
Polyglot
Creating a polyglot is trivial, as CLAG ignores all invalid characters. This means that a polyglot can be created for a language that has a non intersecting set of characters, and similarly ignores invalid characters.
The following program is a CLAG - brainfuck polyglot hello world
++++++++[>+++оօօoօoօоoооооօօoοоοo+[>++>+++>+++>+<<<<-]>+oооооօօoοoοоoоооо>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.-- օօoοoοоoооооօօoοoοοoооооօοоօоoооооօօoօօοοoооооօօoοoοοoооооօօoοօօօoооооօօoοoοоoооооօօoοо----.--------.>>+.>++.οоoооооօοоօooо
Interpreters
CLAGy
CLAGy is a CLAG interpreter and transpiler to brainfuck, created a day after the original interpreter. It is written in python.
pyCLAG
pyCLAG was the original CLAG interpreter. It is very slow, offering no optimization whatsoever.