Conditionalism

From Esolang
Jump to navigation Jump to search

   Author Note: This page is poorly written (by me), please help by suggesting reorganization if possible!

Conditionalism is a stack-based esoteric language created by Blair Myhre in 2023. It follows the concept that in order for x to happen, y must be true; in order for y to be true, two items of x must be identical. Conditionalism uses two stacks. The first is a stack of actions to be executed (stack x), and the second is items to be compared (stack y). This allows its base concept to be applied as in order for the next action of x to run, the two items of y must be the same. To do this, items are popped from the first stack to the second and compared there. These stacks work on a first in, last out basis.

Syntax

The overall syntax of Conditionalism is similar to a standard language.
Note: syntax described below is written in Nearley, which is similar to EBNF.

Modifying Either Stack

modify -> stackname "." method ";"
method -> push | pop | give
stackname -> "x" | "y"
value -> [0-9]:* | "\"" . "\"" | ("true" | "false")

Push

Add a value to a stack:
push -> "push" _ "(" _ (value | (value "," _):* value) _ ")" ";"

~Push a value to Stack x
x.push("print('hello, world!')");
x.push(5);

Items can only be pushed to Stack x; items must be given to stack y

Pop

Remove the top value from a stack:
pop -> "pop" _ "(" _ (value | (value "," _):* value) _ ")" ";"

~Pop the top value from Stack x
x.pop();

Give

Transfer the top item from one stack to the other:
give -> "give" _ "(" _ stackname _ ")" ";"

~Give the top item of x to y
x.give(y);

Execution

Syntax

Executing code can be done with the exe(i, catch); method.
execute -> "exe" _ "(" ((integer:? ("," _ catchtype):?):? | catchtype:?) ")" ";"
iOptionally specify an integer to determine how many actions will run before pausing (quantity, NOT index). By default, all actions will run.
catchOptionally specify how to respond to failure. By default, execution will end on the first invalid comparison.

Concept

Executing code will begin with comparing the top two items of Stack y.
If they are identical, for instance item 1 is 5; item 2 is 5, it will successfully run and then pop the top action of Stack x and pop the top of Stack y. Only one of the compared items will remain.
If they are not identical, for instance item 1 is "hello"; item 2 is "world", execution will either end on the first instance of an invalid comparison (catch type "end", see above) or log the failure and continue (catch type "continue", see above).

Stack items

A stack can contain a string, integer or boolean.
Integers and booleans pushed to stacks can be simply put as a value, like x.push(5); or x.push(true);.
Strings can be any string encased in the standard "" double quote symbols. While they can be used for comparison like other primitives, they can also be lines of code. The ideal way to implement Conditionalism is to have a way to run strings of its implementation language, like the JavaScript eval() function.
Treat Stack x like a source file of code. The top item of Stack x is the first line of a file. When code is run it is basically building a source file to run, omitting integers and booleans on the stack. When the last line of code has been run, the code that has been built will be executed.

Example

Hello World

For a theoretical JavaScript implementation, you can print "Hello, World!" like so:

x.push(5);
x.push(5);
x.give(y);
x.give(y);
x.push("console.log('Hello, World!')");
exe();

Add x + y

For a theoretical JavaScript implementation, you can create a function to add x + y:

x.push("function math(x, y) { return x + y }");
x.push("console.log(math(5, 10))");
x.give(y);
x.push("console.log(math(5, 10))");
x.give(y);
exe();
y.give(x);
x.push(5);
x.give(y);
x.push(5);
x.give(y);
exe();