Codan

From Esolang
Jump to: navigation, search

Codan is an esoteric programming language designed specifically to annoy people who cannot figure out how to input Unicode. Most of its syntax is outside basic ASCII.

Language overview

The language operates on a vector of memory cells of unspecified length, similar to brainfuck's tape. Each of these cells holds a signed integer, and is initialised to 0. Additionally, there are three registers, Α, Β, and Λ (capital alpha, beta, and lambda; note that these are not the Latin ASCII A and B). Α and Β hold reference to locations on the tape, and can be dereferenced using α and β. Λ is the I/O register; trying to read from it will prompt the user for input (in the form of a number), and trying to store a number in it will output it to the screen.

The arrow operators ← and → move values (from memory cells, I/O, or literal constants) into memory cells, or change which cells Α or Β point to. x → y is completely equivalent to y ← x.

The functions +, −, ×, ÷, and ↑ (addition, subtraction, multiplication, division, and exponentiation) operate on the memory locations pointed to by Α and Β.

Finally there is the loop construct, delimited by « and ». On its own it loops forever, so you can place assertions inside, which will break out of the (innermost) loop if they are false. Assertions can use the operators =, ≠, <, ≤, >, ≥, ≮, ≯, ≰, or ≱ for comparison.

Examples

Just to demonstrate the syntax, the following piece of code prompts the user for a number, and then keeps incrementing that number by 1 until it equals 100, at which point it outputs it. All whitespace is optional.

Α ← 0        # Α points to memory location 0
Β ← 1        # Β points to memory location 1
β ← 1        # The value at Β is 1
α ← Λ        # Prompt user and store input at Α
«            # Loop
    α ≠ 100  # Assert that α does not equal 100
    + → α    # Add α and β and store result at Α
»
α → Λ        # Output α

Factorial

The factorial is the Hello, world! of numerical languages. This program also demonstrates direct assignment to memory cells, without going through Α and Β.

1 ← Λ
1 → 2
1 → 3
Α ← 1
Β ← 2
«
    α ≰ 0
    × → 2
    Β ← 3
    − → α
    Β ← 2
»
β → Λ

Fibonacci sequence

The following program will output the Fibonacci sequence for as long as it can before the datatype overflows and wraps around. On implementations that support arbitrarily large integers, that may be forever.

Α ← 1
Β ← 2
α ← 0
β ← 1
«
    α ≮ 0
    α → Λ
    + → 3
    α ← β
    Α ← 3
    β ← α
    Α ← 1
»

Prime number sieve

This outputs all prime numbers below 1000, using Eratosthenes' famous algorithm.

Α ← 2
Β ← 2
«
    Α ≤ 1000
    «
        α = 0
        Α → Λ
        α ← Α
        Β ← Α
        «
            0 ← Β
            0 → Β
            + → Β
            Β ≤ 1000
            1 → β
        »
        0 = 1
    »
    α ← Α
    0 → Β
    1 → 0
    + → Α
»

Turing completeness

Translating Brainfuck programs into Codan programs is relatively straightforward. If a program has been initialised with Β ← 0 β ← 1 Α ← 2, the following equivalences apply:

Brainfuck Codan
> 1 ← Α Α ← 1 + → Α
< 1 ← Α Α ← 1 − → Α
+ + → α
- − → α
. α → Λ
, α ← Λ
[ « α ≠ 0
] »

Since Brainfuck is Turing complete, this means Codan is too.

External resources