Parenthesys
Parenthesys is an esolang by User:TBPO. It's name is very misleading because it rarely uses parentheses.
Underlying structure
Memory
Parenthesys uses infinite global variable namespace, infinite function namespace and local variable namespaces. Each function has one two-variable local namespace. Every variable is initially zero and every user-defined function initially does nothing.
Unlike many other programming languages, in Parenthesys variable and function names are evaluated as normal expressions.
Data types
There are two data types: number and string. A number is a floating point number with arbitrary but finite precision and arbitrary size. It must match regular expresion -?[0123456789]+(\.[0123456789]+)?
. Data types are completely interchangeable, but a TypeError is raised is the string isn't a valid number.
Nesting and expressions
Parenthesys is nested, because every expression to one of these. There are three types of expressions:
- Literals - single characters that return themselves. Digits return numbers and everything elso return strings.
- Concatention - if two values are next to each other, they are glued up to a single value. The result is a number if one of arguments is a number and the result is a valid number.
- Instructions - special expressions that do something useful.
Instructions
(x) | Prints and returns x. |
$ | Gets input. Returns it as a number if it's a valid number and a strong otherwise. |
{x} | Returns x as a number. |
<x> | Returns x as a string. |
[x] | Return value of variable x. |
[x|y] | Save x in variable y and return x. |
[f|x|y] | Apply x and y to function f and return the result. |
[f|x|y|z] | (re)Define function f using expression z on local variables a and b. Return the name of function f. |
{x|y} | While x is non-empty and non-zero, do y. Return concatented results of each itaration. |
\c | Returns string containing only c. |
Built-in functions
Some functions are built-in. They cannot be redefined.
+ | Return x+y. |
- | Return x-y. |
* | Return x*y. |
/ | Return x/y to implementation-dependent precision. |
% | Return x mod y. |
^ | Return xy. |
= | Return 1 if x=y after converting to strings and 0 otherwise. |
! | Return 0 if x=y after converting to strings and 1 otherwise. |
gt | Return 1 if x>y and 0 otherwise. |
lt | Return 1 if x<y and 0 otherwise. |
ind | Return index x of string y, countng from 0. |
len | Return length of string x. |
chr | Convert number x to single UTF-8 character and return result. |
ord | Convert the first chracter of string x to its UTF-8 code and return result. |
tpe | Return 1 if data types of x and y are equal and 0 otherwise. |
Errors
Parenthesys has the folowing errors:
- SyntaxError - invalid syntax.
- TypeError - string being converted to a number is not a valid number.
- ValueError - applying incorrect argument into a built-in function.
- AccessError - trying to redefine a built-in function.
Computational class
Parenthesys is Turing-complete because I/D machine can be converted to it (spaces added for clarity):
I/D machine | Parenthesys |
---|---|
start | {1| |
I | [[+|[p]|1] |[p]] |
D | [[p]|p] |
end | } |
Parenthesys Solid
Parenthesys Solid is subset of Parenthesys in which:
- Variables can't hold strings and user-defined functions can't return strings - in such case the program isn't valid,
- Variable and function names can't contain instructions - in such case the program isn't valid.
Despite limitations Parenthesys Solid is still Turing-complete, which is shown by the Bitwise Cyclic Tag equivalement interpreter below:
(Program: )[{$}|a]( Data: )[{$}|b][+*|x|y|[[+|[*|y|4]|x]|[y]]][dl|x|op|{[![lt|[x]|4]]|[[%|[x]|4]|c][-|[x]|[c|4]|x][+*|c|y]}[[x]|z][[op|[x]|0]|x]{[gt|[y]|0]|[[%|[y]|4]|c][[/|[-|[y]|[c]|4]|y][+*|c|x]}[[x]|r]][0|x|y|0][1|x|y|[x]]{[b]|[dl|[a]|0][[r]|a][+*|z|a]{[=|[z]|0]|[4|z]}{[*|[lt|[z]|3]|[=|[dl|[b]|1]|1]]|[+*|z|b][4|z]}{[=|z|2]|[+*|z|b][4|z]}{[=|z|3]|[dl|[b]|0][4|z]}}
The program gets the program and the data as base-10 numbers from input and treats them as base-4 numbers. Conversion from the equivalement to Bitwise Cyclic Tag is shown below:
0 | 1 | 2 | 3 | |
---|---|---|---|---|
Program | - | 11 | 10 | 0 |
Data | - | 1 | 0 | 0 |
Examples
Hello world
(Hello, world!)
Cat program
($)
Truth machine
[$|a]{[a]|(1)}(0)