DEV Community

Vivian Dai
Vivian Dai

Posted on • Edited on • Originally published at viviandai.hashnode.dev

Hello World: Stuck

Let's start off the series with Stuck, a language where an empty file will output "Hello, World!"

Code

Enter fullscreen mode Exit fullscreen mode

That's it, no code. An empty file in Stuck will print "Hello, World!".

How Does This Work?

We can take a look at the Github repository for Stuck and check out the source code.

GitHub logo kade-robertson / stuck

A stack-based esoteric programming language.

Stuck

Stuck is an esoteric, stack-based programming language intended for code-golf. It was inspired by many languages, such as CJam, GolfScript and Pyth. It is interpreted in Python, and it is very easy to translate Python code to the equivalent Stuck code.

There is some barebones documentation available on the Esolangs page.




In the stuck.py file, we can check out the main function:

def main():
    if len(sys.argv) < 2:
        while True:
            prog = raw_input("stuck > ")
            if prog == 'plugin':
                r=import_modules('plugins')
                for k in r:
                    print '%s - Version %s - By %s\n   %s'%(r[k].NAME, r[k].VERSION, r[k].CREATOR, r[k].DESCR)
            elif prog == '':
                print 'Hello, World!'
            else:
                process(prog, stack=[], t=0, nest=0)
    else:
        if sys.argv[1].split('.')[-1] == 'stk':
            f = open(sys.argv[1], 'r')
            prog = f.read()
            if prog == 'plugin':
                r=import_modules('plugins')
                for k in r:
                    print '%s - Version %s - By %s\n   %s'%(r[k].NAME, r[k].VERSION, r[k].CREATOR, r[k].DESCR)
            elif prog == '':
                print 'Hello, World!'
            else:
                process(prog, stack=[], t=0, nest=0)
        else:
            print 'Usage: python',__file__.split('/')[-1],'program.stk'
Enter fullscreen mode Exit fullscreen mode

Do you see it?

elif prog == '':
           print 'Hello, World!'
Enter fullscreen mode Exit fullscreen mode

The Stuck interpreter will print "Hello, World!" when the file is empty.

Conclusion

Esolangs are fun and help solidify an understanding of computers and programming. Stay tuned for the next language!

Top comments (0)