DEV Community

JavaCode7
JavaCode7

Posted on • Edited on

3 1

Improving the esolang

So I wrote an article making an esolang and got this comment:
The dev.to comment that instigated the writing of this article
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()
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

And there we have it! The esolang has been improved. I hope you like this article.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay