Onov

From Esolang
Jump to navigation Jump to search

ONOV (Only Names Of Variables) is a language made by User:Boyss where the whole code always consists only of names of variables.

Definition

Any string of characters tolerated by Python is a valid ONOV program. The execution goes like this:

  1. Accept that True is 1 and False is 0
  2. The code is recursively separated into halves.
  3. Products of the first operation are listed as "torches", which are boolean type variables with a list of "givers". Every two names of variables the second one will have the previous as their giver. All torches have their states set to False.
  4. There is made a copy of all torches.
  5. Every torches' states are set to False.
  6. If there is something in the input list, the leftmost element gets popped and the first declared torch's state is set to it's value.
  7. For every torch, if at least one of their givers' state is False in the copy their state becomes True.
  8. The last declared torch's state is added to the right of the output queue.
  9. If the output queue has less than 7 elements in it go back to point 4
  10. Else, if it's seven times True get console input. Clear the input list. For every character in the input, add string of bits representating it's number in ASCII to the right of the input list. Go back to point 4
  11. Else, if it's seven times False exit the program.
  12. Else, print the character that is in ASCII represented by the number which would output queue be in binary if readen from left to right.
  13. Erase everything from the output queue and go back to point 4

Examples

Infinite cat

Any code with an odd length will be a infinite cat program.

A

Inspiration

The name for variables (torches) comes from negating block in redstone circuits in Minecraft

Implementation

Implementation in Python 2.7.10

 #Python 2.7.10
 #ONOV language interpreter
 from sys import stdout, exit
 from sre_constants import IN_IGNORE
 write=stdout.write
 
 def dec(binary_num):
    return int(binary_num, 2)
 
 def stringify(x):
     ret=bin(ord(character))[2:]
     while len(ret)<7:
         ret='0'+ret
     return ret
     
 
 def part(S):
     l=len(S)
     if l%4==0:
         return part(S[:l/2])+part(S[l/2:])
     elif l%2==0:
         return [part(S[:l/2]),part(S[l/2:])]
     else: return S
 
 def part1(S):
     x=part(S)
     if isinstance(x, list):
         return x
     else:
         return [x]
      
 class Torch:
     def __init__(self,giver,name):
         self.name=name
         self.state=False
         if giver:
             self.givers=[giver]
         else:
             self.givers=[]
         
 code=file(raw_input("""
 Please enter name of the file to interpret\n""")).read()
 parted=part1(code)
 torches=[]
 current=False
 for x in parted:
     repeated=False
     for torch in torches:
         if torch.name==x:
             if current: torch.givers.append(current)
             repeated=True
     if not repeated: torches.append(Torch(current,x))
     current=False if current else x

 out=''
 in_=[]
 while True:
     copy=torches
     for x in torches:
         x.state=False
     if in_:
         torches[0].state=True if int(in_.pop(0)) else False
     for x in torches:
         for name in x.givers:
             for torch in copy:
                 if name==torch.name and not torch.state:
                     x.state=True
     out+=str(int(torches[-1].state))
     if len(out)==7:
         if out=='0'*7:
             in_=[]
             for character in raw_input():
                 for x in stringify(character):
                     in_.append(x)
         elif out=='1'*7:
             exit()
         else:
             write(chr(dec(out)))
         out=''