Patience
Patience is an esoteric programming language created by User:ThrowAwayLurker in Category:2025. Instructions and data are mixed together, stored on a queue. It has 6 primitive data types, including functionals, plus null.
The code of a program describes the initial state of the queue. Each item on the queue is separated by semicolons. Execution is done as follows:
- If the front of the queue is a functional, dequeue and run it. Any and all return values are queued.
- If the front of the queue is not a functional, dequeue requeue it. In other words, values at the front of the queue get rolled.
As something is guaranteed to occur every step if nonempty, a program is considered halted if it contains no functionals. This condition includes empty programs as halted, thus this is the only condition needed.
The datatypes and their literals are:
| Type | Literal format |
|---|---|
| Null | null.
|
| Boolean | true or false.
|
| Integer | A decimal number which has no decimal point. |
| Floating point | A decimal number which must have a decimal point. |
| String | A string of characters circumfixed with quotation marks. Backslashes can be used as escape characters. |
| Array | Values circumfixed with curly brackets and separated by commas. A trailing comma is required, even for the empty array. |
| Functional | Values circumfixed with curly brackets and separated by semicolons. A trailing comma is required, even for the empty functional. |
Operations
When a functional is run, each value in it is evaluated successively, with each result being returned. Returned values are enqueued, except for null, which doesn't get queued when returned. Note that "evaluation" doesn't mean functionals inside of functionals are executed; it is thus similar to a simplification process. The following operations are evaluated during the evaluation process:
| Symbol | For Booleans | For integers | For floating points | For strings | For arrays | For functionals |
|---|---|---|---|---|---|---|
a + b |
Computes the OR | Computes the sum | Computes the sum | Computes the concatenation | Computes the concatenation | Computes the concatenation |
a - b |
Computes the XOR | Computes the subtraction | Computes the subtraction | If a ends in b, remove the end; else a |
If a ends in b, remove the end; else a |
If a ends in b, remove the end; else a
|
- a |
Computes the negation | Computes the negation | Computes the negation | -- | -- | -- |
a * b |
Computes the AND | Computes the product | Computes the product | Computes the intersection, with the order of a preserved; allows duplicates if duplicates exist in the other string |
Computes the intersection, with the order of a preserved; allows duplicates if duplicates exist in the other array |
Computes the intersection, with the order of a preserved; allows duplicates if duplicates exist in the other functional
|
a / b |
Computes the implication a->b | Computes the floored division | Computes the division | Removes all substrings of b present in a |
Removes all subarrays of b present in a |
Removes all subfunctionals of b present in a
|
a == b |
Computes equality | Computes equality | Computes equality | Computes equality | Computes equality | Computes (symbolic) equality; {5;} == {5;} returns true, while {3+2;} == {5;} returns false
|
a > b |
true if a is true and b is false |
Checks if a is greater |
Checks if a is greater |
Checks if b is a substring of a |
Checks if b is a subarray of a |
Checks if b is a subfunctional of a
|
a < b |
true if a is false and b is true |
Checks if b is greater |
Checks if b is greater |
Checks if a is a substring of b |
Checks if a is a subarray of b |
Checks if a is a subfunctional of b
|
a === b |
true |
true |
true |
true |
true |
true
|
==, >, <, and === give false if the types are unequal, and the other operations raise an error if the types are unequal; except for null, which gets converted to false, 0, 0.0, "", {,}, or {;} before evaluation, depending on datatype of the other argument. null is not converted if the operation is ===. Blank entries in the table also raise errors.
The negatives of ==, >, <, and === are !=, !>, !<, and !==.
Additionally, there are operations not described above which can accept and usually do accept arguments of different types:
| Symbol | Description |
|---|---|
if a: (b) |
If a != null, is b, else is null
|
a else (b) |
If a === null, is b, else is a
|
a in b |
If b is a sting, array, or functional, true if a is in b
|
a[b] |
If a is a sting, array, or functional and b is an integer, is the bth member of a (0-indexed); if a is a sting, array, or functional and b is not an integer, is the index of the first instance of b in a (-1 if b is not in a)
|
Furthermore, the expression queue(n) for integer n gives the value at position n in the queue; queue(0) gives the this currently being evaluated, queue(1) gives the value after the front of the queue, etc. If n equals or exceeds the queue's length, or is negative, gives null. All values accessed by queue(n) are dequeued after evaluation of the rest of the functional finishes. in gives null and enqueues user input. print a prints the value of a.
The following can be used to cast the data types of values:
| Symbol | For Booleans | For integers | For floating points | For strings | For arrays | For functionals |
|---|---|---|---|---|---|---|
bool(a) |
-- | a == 0 |
(a == 0.0) + (a == -0.0) |
true if a is nonempty |
true if a is nonempty |
true if a is nonempty
|
int(a) |
if a: (1) else (0) |
-- | Floor of a |
The length of a |
The length of a |
The length of a
|
flt(a) |
if a: (1.0) else (0.0) |
Closest floating point to a, going up if there is a tie |
-- | If a is in the format of a integer or floating point literal, gives the closest floating point to that; else null |
null |
null
|
str(a) |
How the literal for a would be written |
How the literal for a would be written |
How the literal for a would be written |
-- | How the literal for a would be written |
How the literal for a would be written
|
arr(a) |
The singleton array containing a |
The singleton array containing a |
The singleton array containing a |
The array of each character of a |
-- | The array of each element functional of a
|
func(a) |
The functional which simply queues a |
The functional which simply queues a |
The functional which simply queues a |
The functional which simply queues a |
The functional whose instructions are the elements of a |
-- |
Blanks here represent no modifications.
Examples
One-time cat
{in; print queue(1);};
Infinite cat until empty string
{in; print queue(1); if queue(1) != "": (queue(0));};
Truth machine
{if queue(1) === null: (in); if queue(1): (queue(0)); print queue(1);};
Fibonacci sequence
{queue(0); print queue(1); queue(2); queue(1) + queue(2);}; 0; 1;
Fizzbuzz
{if queue(1) / 15 * 15 == queue(1): (print "Fizzbuzz")
else if queue(1) / 5 * 5 == queue(1): (print "Buzz")
else if queue(1) / 3 * 3 == queue(1): (print "Fizz")
else (print queue(1));
queue(0); queue(1) + 1;};
1;