IP

From Esolang
Jump to navigation Jump to search

IP is a stack-based esolang designed by User:iddi01 in which programs looks somewhat like IP addresses.

Description

The only valid commands are the digits, ".", and "-".

Dots slices each program into sections, in which the sequence of numbers will be converted into a single integer for use with several different commands.

Commands

. Pops an item from the stack, check if it's equal to the section before the ".", then push it back. If not equal, skip the next instruction.
- Indicates the section is a negative number
0 Pushes the current section to the stack
1 Pops an item from the stack and prints it as number/ASCII (up to the implementation)
9 Pops two items (a, b) from the stack and push back a - b
Other even digits - Go (digit) characters forward
Other odd digits - Go (digit) characters back

Examples

All examples assume input is already stored in the stack.

Hello, World!

(not yet)

Cat program

1113

Truth-machine

40.0.82.01.3

Fibonacci sequence

(not yet)

Looping counter

(not yet)

Looping but not counter

01.3

Quine (using number output)

2001

Computational class

Because both storage and programs are unbounded in IP, it could be Turing-complete. However a proof would be extremely difficult to make, since it's extremely difficult to program anything with the slightest bit of complexity in IP.

Implementation

Python (moderate)

import copy
pos = 0
stack = []
program = input("Program: ")
def getsect():
   tempos = pos - 1 if pos > 0 else pos
   while tempos > 0 and program[tempos] != '.':
       tempos -= 1
   tempos2 = copy.copy(pos)
   while tempos2 < len(program) and program[tempos2] != '.':
       tempos2 += 1
   return int(program[tempos:tempos2].replace('.', ""))
while True:
   try: char = program[pos]
   except IndexError: break
   if char == '.':
       try:
           temp = stack.pop()
           if temp != getsect():
               pos += 1
           stack.append(temp)
       except IndexError: ...
   elif char == '0':
       stack.append(getsect())
   elif char == '1':
       try: print(chr(stack.pop()), end="")
       except IndexError: print(' ', end="")
       except ValueError: print(' ', end="")
   elif char == '9':
       try: stack.append(stack.pop() - stack.pop())
       except: ...
   elif char == '-':
       ...
   elif int(char) % 2 == 0:
       pos += int(char) - 1
   elif int(char) % 2 == 1:
       pos -= int(char) + 1
       if pos < -1: break
   pos += 1