This content originally appeared on DEV Community and was authored by JavaCode7
So I wrote an article making an esolang and got this comment:
Thanks to @olus2000
for this comment.
Here is the full code so far:
value = 0
code = input("Enter your loo code here please > ")
lexed = []
for i in code:
lexed.append(i)
for j in lexed:
if j == "+":
value += 1
elif j == "-":
value -= 1
elif j == "#":
print(chr(value))
elif j == ";":
quit()
In this guide, I am going to add a quine (quine prints out the code), a way to specify how much you want to increment or decrement by putting a number between 1 and 9 inclusive before +
or -
and finally, I am going to add numeric printing.
Step 1: quine
The quine functionality can easily be implemented by adding another branch to the if statement.
elif j == "q":
print(code)
Step 2: improving +
and -
To make the changes to +
and -
, we are going to have to modify the for loop. This must be done to make sure we can access the index. This will be useful later.
for k in range(0, len(lexed) - 1, 1):
j = lexed[k]
if j == "+":
value += 1
elif j == "-":
value -= 1
elif j == "#":
print(chr(value))
elif j == ";":
quit()
elif j == "q":
print(code)
From here, we then have to modify the +
and -
branches to make the changes
for k in range(0, len(lexed) - 1, 1):
j = lexed[k]
if j == "+":
scale = int(lexed[k - 1])
value += scale
elif j == "-":
scale = int(lexed[k - 1])
value -= scale
elif j == "#":
print(chr(value))
elif j == ";":
quit()
elif j == "q":
print(code)
Step 3: numeric printing
After the changes made in step 2, it is now possible to read other tokens given an offset. We are going to use this in numeric printing as well.
for k in range(0, len(lexed) - 1, 1):
j = lexed[k]
if j == "+":
scale = int(lexed[k - 1])
value += scale
elif j == "-":
scale = int(lexed[k - 1])
value -= scale
elif j == "#":
if lexed[k - 1] == "|":
print(chr(value))
else: print(value)
elif j == ";":
quit()
elif j == "q":
print(code)
And there we have it! The esolang has been improved. I hope you like this article.
This content originally appeared on DEV Community and was authored by JavaCode7
JavaCode7 | Sciencx (2021-06-05T14:16:12+00:00) Improving the esolang. Retrieved from https://www.scien.cx/2021/06/05/improving-the-esolang/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.