Improving the esolang

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 …


This content originally appeared on DEV Community and was authored by JavaCode7

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()

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


Print Share Comment Cite Upload Translate Updates
APA

JavaCode7 | Sciencx (2021-06-05T14:16:12+00:00) Improving the esolang. Retrieved from https://www.scien.cx/2021/06/05/improving-the-esolang/

MLA
" » Improving the esolang." JavaCode7 | Sciencx - Saturday June 5, 2021, https://www.scien.cx/2021/06/05/improving-the-esolang/
HARVARD
JavaCode7 | Sciencx Saturday June 5, 2021 » Improving the esolang., viewed ,<https://www.scien.cx/2021/06/05/improving-the-esolang/>
VANCOUVER
JavaCode7 | Sciencx - » Improving the esolang. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/05/improving-the-esolang/
CHICAGO
" » Improving the esolang." JavaCode7 | Sciencx - Accessed . https://www.scien.cx/2021/06/05/improving-the-esolang/
IEEE
" » Improving the esolang." JavaCode7 | Sciencx [Online]. Available: https://www.scien.cx/2021/06/05/improving-the-esolang/. [Accessed: ]
rf:citation
» Improving the esolang | JavaCode7 | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.