esolang

Logical

A language that does not do what you think it should. Every name is a lie, and every error succeeds.

David.werecat, 2012 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: hello, world!

The idea

David.werecat made Logical in 2012. Every line is a comment until you mark it as a comment with COMET. GOTO assigns, SET adds, MUL subtracts, DEFN prints and DIV exits. The source must be all upper case, but it is read in lower case. A ~ gives the interpreter a nervous breakdown, and any error stops the run with the message ERROR: THE OPERATION COMPLETED SUCCESSFULY.

Read the story

Values are just as twisted. The integer 123 is written "-123". A string is written backwards with _ for spaces. A variable is renamed the moment it is defined, to ROT13 of the variable defined before it, so the first one is always called YBTVPNY. The first value you give a variable is thrown away; it only sets the variable's type, to the opposite of its own.

The machine

StatementDoes
GOTO v xv = x
SET MUL UNDF DOIF v x yv = x + y, x - y, x * y, x / y
SUB nDefine a variable
ADD nDefine a label
DEFN xWrite x
EXIT vRead a character into v
LABL x c yRun the next statement only if x c y is false
INPT -n OPEN -nJump to label n; call it
CONVReturn from a call
FUNC v xv = the character with code x
WRIT nUndefine a variable
DIVExit
ERRORNothing

A label is named by its number typed with shift held, so 123 is !@#, and it is called as -123. A jump lands three lines before the label. OUTP, RETN, CLOS and READ open, read, write and close files, which live only for the run. The comparisons are ==, !=, <=, >=, << and >>.

Example

Hello World.

Hello World. Backwards it says HELLO,_WORLD!, and the lower case reading prints it small.

Expected: 42

SUB X makes a variable called YBTVPNY. Giving it the string a makes it an integer, and UNDF multiplies 6 by 7.

The cat jumps with INPT -123 to three lines above ADD !@#, which is its EXIT. Reading past the end of the input is an error, so the cat ends with the message.

Expected: CATERROR: THE OPERATION COMPLETED SUCCESSFULY

The Fibonacci program prints 1, 1, 2 and on to 832,040, each followed by , .

Patterns it teaches

  • Hostile design: names that mean something else, and errors that report success.

Further

Also in Jokes

Write your own in Run Convert a program from Logical

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: logical.

Command line

shib run logical -e 'COMET DEFN !DLROW_,OLLEH'
shib manual logical

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/logical.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org