Where

From Esolang
Jump to navigation Jump to search

Where is an esoteric programming language created by User:Ketok.

Language overview

Where operates on 4 memory cells, initially set to 1, 2, 3, 4. Each cell can contain value ranging from 0 to 255.

Statements

Where statement

Syntax:

WHERE condition action

Where statement executes action on all cells satisfying the given condition.

For example:

WHERE >2 SET 255

will set all memory cells with value higher than 2 to 255.

While statement

Syntax:

WHILE [ANY|ALL] condition
    ...
END

While statement executes its contents while all/any cells satisfy the given condition.

Reset statement

Syntax:

RESET

Reset statement resets values of all cells to their initial state. It's mainly intended to be used in the interactive mode.

Conditions

  • =n
  • <n
  • >n

Actions

  • SET value
  • ADD value
  • SUB value
  • INPUT
  • OUTPUT

Interactive Mode

Interactive mode is a feature added in v0.2.0 release used to run Where code interactively in the terminal. In other words it executes REPL (Read, Evaluate, Print Loop) for Where. It can be entered by running Where interpreter without any command line arguments.

Examples

Truth machine

# Truth machine
WHERE =1 INPUT
WHERE =0 OUTPUT
WHILE ANY =1
    WHERE =1 OUTPUT
END

Adder

# A simple program that adds two numbers together
WHERE >1 ADD 251
WHERE =1 INPUT
WHERE <253 ADD 128
WHERE =253 INPUT
WHERE >253 SET 0
WHILE ANY >128
    WHERE >128 SUB 2
    WHERE >0 ADD 1
END

WHERE =0 SET 255
WHERE <128 OUTPUT

Interpreter

Interpreter for Where is written in F# with FParsec. It can be downloaded from github.