UnnumericPy

From Esolang
Jump to navigation Jump to search

UnnumericPy is an esoteric programming language created by User:Marina and inspired by UnnumericJS. It is an equivalent to Python, but if the code has any digits it will raise a syntax error.

Examples

Hello world

print("Hello World")

Cat program

i = input(">>>")
print(i)

Truth machine

a=input(">>> ")
if a==str(int(False)):
    print(int(False))
elif a==str(int(True)):
    while True:
        print(int(True))
else:
  raise Exception

Here, int(False) and int(True) are used for 0s and 1s.

A shorter one that doesn't use number literals (int(False) and int(True)):

a=input(">>> ")
if int(a):
    while ' ':
        print(a)
else:
    print(a)

Syntax error

0

Interpreter

Python

def unnumericpy(code):
 for i in range(10):
   if str(i) in code:
     raise SyntaxError("syntax error")
 exec(code)

Expressiveness

All of Python can be expressed in UnnumericPy.

Literals

We replace integer, floating-point, and complex literals first. The integers can be generated from arithmetic on -1, 0, and 1. The literals True and False can be used as 0 and 1. -1 is constructed as ~0. They can also be constructed from the integer constructor:

int()     # 0
~int()    # -1
-(~int()) # 1

The floating-point numbers are generated as ratios of integers using the true-division operator. The special cases do not require digits:

float("nan")
float("inf") # and float("-inf") or -float("inf")

Complex numbers are built using their constructor instead of literals.

Names

Next, we recover the ability to access names containing digits. To access a local or global, use the string constructor and string concatenation to build the name as a string, then use it as a key on the corresponding scope dictionary. For example, to access the local name "x2":

locals()["x" + str(-(~int() + ~int()))]

This generalizes to imports as well, since package names are passed as strings. For example, to import the standard-library module "sqlite3":

from importlib import import_module
three = -(~int() + ~int() + ~int())
sql = import_module("sqlite" + str(three))

Turing completeness

Because all of Python is still expressible, UnnumericPy is trivially Turing-complete.