Quil

From Esolang
Jump to navigation Jump to search

Quil is an esoteric programming language made by User:Fly in year 2026 and it was specifically made to feel weird to use.

How it works

At the start of the program, a counter is set to 0. That counter decides the current state of the program, control flow and arithmetic. You can store states of the counter using variables and can set the counter to any variable any time you want in the program.

Instructions

Instruction Description
+ Increment the counter by one
- Decrement the counter by one
N Set the counter to N
[nameVariable]= Assign to nameVariable the current state of the counter
[nameVariable] Set the counter to whatever nameVariable is
N/nameVar[...] Check if the counter is equal to N or nameVar, and if true execute the code inside [...]
{...} If before the { there's N or nameVar it will loop until that value, otherwise it loops indefinitely
? Take an input as a number and set the counter to that input
% Output the counter as a number
! Output the counter as it's corresponding ASCII
& Break from a loop
; Stop the program

Examples

Calculator

? numOne=
? numTwo=
? op= 
10 LF=

op 1 [
    numTwo 0 {
        numOne + numOne=
        numTwo - numTwo=
    }
] op 2 [
    numTwo 0 {
        numOne - numOne=
        numTwo - numTwo=
    }
] op 3 [
    numOne K=
    numTwo- numTwo=
    numTwo 0 {
        K i=
        i 0 {
            numOne+ numOne=
            i- i=
        }
        numTwo- numTwo=
    }
] op 4 [
    numTwo K=
    0 c=
    numOne numTwo [
        0 numOne=
    ]
    numOne 0 {
        c+ c=
        K i=
        i 0 {
            numOne - numOne=
            i - i=
        }
    }
    c+ numOne=
]

numOne%LF!

Infinite loop

{}

Count from 1 to 10

from=
10 to=

from to{
    from+ %10!
    from+ from=
}

Truth-machine

?
1 [
    {%} 
] 0 [
    %
]

Factorial

? n=
n- next=

next 0 {
    n K=  
    next- nxt=  
    nxt 0 {  
        K i=  
        i 0 {  
            n+ n=  
            i- i=  
        }  
        nxt- nxt=  
    }
    next- next=
}

n%10!

Fibonacci

? n=
0 a=
1 b=
a cA=

n 0 {
    a%32!
    b a=
    
    b 0 {
        cA+ cA=
        b- b=
    }
    cA b=
    a cA=

    n- n=
}

Compare two numbers

? nO=
? nT=

nO nT [ 61!10!; ]

nO 0 {
    nT- nT=
    nT 0 [
        62!10!;
    ]
    nO- nO=
}
60!10!

Number guessing game

71!117!101!115!115!32!97!32!110!
117!109!98!101!114!32!102!114!
111!109!32!49!32!116!111!32!49!48!48!10!
37 n=
{
	84!121!112!101!32!121!111!
	117!114!32!103!117!101!115!
	115!58!32!
    ? guess=

    guess nO=
    n nT=
    nO nT [ 67!111!114!114!101!99!116!33!10!& ]
    nO 0 {
        nO- nO=
        nT- nT=
        nT 0 [
            84!111!111!32!104!105!103!104!10!&
        ]
        nO 0 [
            84!111!111!32!108!111!119!10!&
        ]
    }
}

Computational class

Quil is Turing Complete because it can simulate a 2-register Minsky machine.

Suppose RO is the first register and RT is the second, then we can write this to make an adder:

3 RO=
2 RT=

RT 0 {
    RO+ RO=
    RT- RT=
}
RO%10!
RO+ RO=  <--->  INC RO
RT 0 {code} something_else <---> DEC RT, code, something_else

Implementations

Python interpreter: https://github.com/mmmmosca/Quil