Fear of the Unknown

From Esolang
Jump to navigation Jump to search

Fear of the Unknown is an esolang created by User:Fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff in 2024. It's inspired by My Unreliable Past, Entropy, and Subtractpocalypse.

Data storage

Data in Fear of the Unknown is stored in variables, which can be modified by commands. After each command, one of the variables (except the subject of the command) has a chance to 1: increment, 2: decrement (this only happens if the variable is nonzero), 3: not change at all. Options #1 and #2 both have a 25% chance, while #3 has a 50% chance. Variables that are used more as the subject have a higher chance of being picked. All variables except $IO are initially set to 0. $IO is initialized to 1.

Syntax

A command starts with a variable (called the subject), followed by an operator (+, -, =) and then either a number or a variable (called the object), then finally a semicolon. Empty commands are also allowed. Note that = is a loose equality check, not an assignment. Commands are followed in a cyclic order. After a command, if the subject of the command is ever negative, the program halts. Randomization may not halt the program. Comments may be included in the source code, surrounded by a ". Whitespace is disallowed in variable names and numbers, but is permitted everywhere else. All alphanumeric characters are allowed in variable names, along with underscores and dollar signs.

For example, a valid program could be:

A + $IO; A = 65; " Comment " lOnG_vAr2 - 9;
Symbol Name Function
+ Add Increment the subject's value by the object
- Subtract Decrement the subject's value by the object. The program halts if the value becomes negative.
= Equality Set the subject to 1 if it is equal to the object's value and 0 otherwise. If the values are one away, the subject still becomes 1.

Input and output

The variable $IO is special, as it handles input and output. Whenever $IO is the subject of either + or - (and nonzero), the object is printed as a Unicode character (if it's nonzero). When $IO is the object (and nonzero) of a command, the value is the Unicode ID of one character of input. $IO may not be changed randomly. End of file returns 1114112. Trying to output an invalid character halts the program.

Examples

Hello, World!

$IO=$IO; $IO+72; $IO=$IO; $IO+101; $IO=$IO; $IO+108;
$IO=$IO; $IO+108; $IO=$IO; $IO+111; $IO=$IO; $IO+44;
$IO=$IO; $IO+32; $IO=$IO; $IO+87; $IO=$IO; $IO+111;
$IO=$IO; $IO+114; $IO=$IO; $IO+108; $IO=$IO; $IO+100;
$IO=$IO; $IO+33; HALT-99;


This program uses the HALT variable to halt. It does not have enough time to get to 99, thus it will always be smaller and halt the program.

Truth-machine (?)

X + $IO; X = 50; X + X; X + X; X + X; $IO + 49; X - 3; $IO = $IO;

Note that this truth-machine outputs a single 1 when the input is 0.

Cat Program

$IO + $IO;

Cat Program (with -e command line option)

A - A; A + $IO; A - 1; A + 1; $IO + A; $IO = $IO;

Full grammar

Here is the full grammar in a BNF-like syntax. (Note that A - B means it matches A but not B)

letter = ( "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m"
         | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
         | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M"
         | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
         | "_" | "$" )
digit = ( "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" )
identifier = letter ( letter | digit )*
number = ( digit )+
not_quote = ( . - '"' )
comment = '"' ( not_quote )* '"'
operation = ( "+" | "-" | "=" )
command = identifier operation ( number | identifier ) ";"
program = ( command | comment )*

Required command-line options

-e

End of file returns 0.

-i

Take in input and store them in variables.