PriLogic

From Esolang
Jump to navigation Jump to search

PriLogic is an esolang by User:BoundedBeans using priority queues as its only data structure.

Storage

PriLogic uses a priority queue of unbounded non-negative integers, where smaller numbers have more priority by default. However, an expression system allows the priority to change around during the execution of the program.

Instructions

Each instruction is preceded by a colon. Whitespace is completely ignored no matter where in the code it is. There are no escape sequences in strings, so that means that double quotes cannot be inside comments or printed using W, however double quotes can be printed using Y

P(number) - put the number into the queue
Q - remove the smallest number from the queue
R"(expression)" - remove a number, apply the expression to it, put it back into the queue
S"(expression)" - change the ordering of the system to the ordering where smaller numbers evaluated 
from that expression are removed first
T"(expression)",[(code)] - remove a number, apply the expression to it, run the code in square brackets
the number of times corresponding to the value
U"(expression)" - if this code is in square brackets, remove a value and evaluate the expression on it, 
if the result is zero, jump execution back to the beginning of the square brackets.
V"" - a comment. Anything inside the quotes is ignored, and so is this command
W"" - print the text in the quotes
X"(expression)" - remove a number and print the value of the expression as a number
Y - print double quote
Z - input a number and put it in the queue

These two commands sort of ruin the spirit a bit, but they are necessary for duplicating values and some expressional things. The name must be only uppercase letters.

A"(name)" - remove a value from the queue, save it into a variable with the name given
B"(name)" - retrieve the value from name and put it into the queue 
(The variable will continue to contain the value after this command)

Expressions

Curly brackets (the equivalent of parenthesis) are required for any expression containing anything other than one infix operator and two numbers or hashtags. To represent just the number put in, you can do something like "#+`0`" or "#*`1`".

# - the parameter
|(name)| - the value of the variable with the name
`(a decimal number)` - that decimal number
+ - add
- - subtract
* - multiply
/ - divide
% - modulo
^ - exponent
= - 1 if the two equal each other, 0 if they don't
> - 1 if the first is greater than the second, 0 if not
< - 1 if the first is less than the second, 0 if not
@ - logical NAND
$ - bitwise NOR only for the least significant 64 bits, the rest set to all zeroes.
% - bitwise NOR, accepting the second argument as both the operand and the number of bits,
with their digits interleaved in decimal (the operand's digits first) and preceded by a 1
(For example, to bitwise NOR 5 and 17 with an accuracy of 24 bits, write "`5`%`11274`")
~ - interleave the two arguments in decimal and precede by a 1, useful for arguments to %
{(expression)} - parenthesis

Examples

Hello world

W"Hello, world!"

Calculator

Give three numbers as input, the first two being the operands as (n+1)*10, the last one being 1 to add, 2 to subtract, 3 to multiply, and 4 to divide. The operands should not be negative, but can be zero.

:Z:Z:Z:A"OPERATOR":A"A":A
"B":T"|OPERATOR|=`1`",[:X
"{{|A|/`10`}-`1`}+{{|B|/`
10`}-`1`}"]:T"|OPERATOR|=
`2`",[:X"{{|A|/`10`}-`1`}
-{{|B|/`10`}-`1`}"]:T"|OP
ERATOR|=`3`",[:X"{{|A|/`1
0`}-`1`}*{{|B|/`10`}-`1`}
"]:T"|OPERATOR|=`4`",[:X"
{{|A|/`10`}-`1`}/{{|B|/`1
0`}-`1`}"]:V"{|:#.:[[$%@"

(This program was designed to be a rectangle to show the complete freedom of whitespace, but programs do not have to be)