We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
√-1
Jump to navigation
Jump to search
√-1 is a stack-based language created by User:Broxol. It is designed to only allow stacking of imaginary numbers.
This language was made from the inspiration page, so I’m not going to really explain it, but I do have some examples.
Unfortunately, I did not add any form of inputting. I’ll fix that in a future version.
EXAMPLES
Hello, World program:
Hello,|World! print
1 + 1 program:
1j 1j 1j 1j * * * dup + print
INTERPRETER
import math
code = "[ 1j 1j 1j 1j * * * dup dup / print ] "
code = list(code)
stack = []
j = 0
new_code = []
setup = []
def is_complex(string):
try:
string = complex(string)
return True
except ValueError:
return False
while j < len(code):
if code[j] == " ":
setup = "".join(setup)
new_code.append(setup)
setup = []
j += 1
elif code[j] == "|":
setup.append(" ")
j += 1
else:
setup.append(code[j])
j += 1
code = new_code
print(new_code)
i = 0
while i < len(code):
if code[i] == "print":
print(stack.pop())
i += 1
elif code[i] == "+":
val1 = stack.pop()
val2 = stack.pop()
val1 += val2
stack.append(val1)
i += 1
elif code[i] == "-":
val1 = stack.pop()
val2 = stack.pop()
val1 -= val2
stack.append(val1)
i += 1
elif code[i] == "*":
val1 = stack.pop()
val2 = stack.pop()
val1 *= val2
if val1.imag == 0:
val1 = int(val1.real)
stack.append(val1)
i += 1
elif code[i] == "/":
val1 = stack.pop()
val2 = stack.pop()
val1 /= val2
if val1.imag == 0:
val1 = int(val1.real)
stack.append(val1)
i += 1
elif code[i] == "dup":
stack.append(stack[-1])
i += 1
elif code[i] == "reach":
stack.append(stack[-stack.pop()])
i += 1
elif code[i] == "]":
if stack[-1] == -1:
i += 1
else:
while code[i] != "[":
i -= 1
elif code[i] == "[":
i += 1
else:
if code[i].isdigit():
assert 0 == 1, f"ValueError: {code[i]} is not a valid value. Maybe your syntax was wrong? Correct form is 1j"
elif is_complex(code[i]) == True:
stack.append(complex(code[i]))
i += 1
else:
stack.append(code[i])
print(stack)
i += 1