Parenthesys

From Esolang
Jump to navigation Jump to search

Parenthesys is an esolang invented 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

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.

Built-in functions
+ 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)

99 bottles of beer

[99|x]{[gt|x|1]|([x] bottles of beer on the wall, [x] bottles of beer. Take one down, pass it around, )[[-|[x]|1]|x]([x] bottles of beer on the wall.)}(1 bottle of beer on the wall, 1 bottle of beer. Take one down, pass it around, No bottles of beer on the wall.)

A+B Problem

([+|$|$])

Quine

[40|0][123|1][91|2][108|3][116|4][124|5][91|6][120|7][93|8][124|9][56|10][56|11][93|12][124|13][92|14][91|15][91|16][91|17][120|18][93|19][93|20][92|21][124|22][91|23][120|24][93|25][92|26][93|27][93|28][124|29][120|30][91|31][91|32][43|33][124|34][91|35][120|36][93|37][124|38][49|39][93|40][124|41][120|42][93|43][93|44][125|45][123|46][91|47][108|48][116|49][124|50][91|51][120|52][93|53][124|54][56|55][56|56][93|57][93|58][91|59][99|60][104|61][114|62][124|63][91|64][120|65][93|66][124|67][93|68][93|69][124|70][121|71][91|72][91|73][43|74][124|75][91|76][120|77][93|78][124|79][49|80][93|81][124|82][120|83][93|84][93|85][125|86][41|87]({[lt|[x]|88]|\[[[x]]\|[x]\][|x[x]|1]|x}{[lt|[x]|88]|[chr|[x]|][|y[x]|1]|x})

This is my first quine, by the way.