Trash

From Esolang
Jump to navigation Jump to search

Trash is an even simpler esoteric programming language invented by User:A that is designed to fullfill the CGCC definition of a programming language.

Syntax

It is very simple (even simpler than my previous function, Garbage, which takes 2 operands):

  • If the parameter is a prime:
    • Return the next prime
  • Otherwise:
    • Return 0.

Proof as a programming language

  1. Support a representation of natural numbers and of tuples. Since Trash supports two-operand addition with natural numbers, this is a check.
  2. Be able either to transform inputs into outputs (transformational model) or to distinguish an "accepted" input from a "rejected" input (decision model). This is done as in the primality checker.
  3. Be able to take a natural number and say whether or not it is a prime. Say we have a t function representing a trash function application:
t4

In this function application, the t function checks whether the number is a prime by either returning a zero value or a nonzero value. (2 is the smallest prime number, and the next prime is 3 and so on, so it isn't possible to have anbiguity.)

  1. Be able to take two natural numbers and add them. Now let us pretend that Trash only accepts prime numbers as input:
2, 3, 5, 7, 11, 13, 17, 19, ...
1, 2, 3, 4,  5,  6,  7,  8, ...

Say we want to increment the number 6. We translate the number to its Trash-number representation (which is in turn 13). The following Trash code does the incrementation:

t13

The result is 17, which is the result that we want. (17 is the 7th prime number.) Now how do we implement addition with multiple parameters in Trash? We represent the other operand in unary as the applications of the t function, of course:

ttt7

The result is 17. We have now successfully added 4 by 3.


Therefore, Trash is indeed a real language.


Implementations

A C++ interpreter by User:Bangyen.