Hello World in Racket

Published on 25 July 2019 (Updated: 25 July 2019)

Hello World in Racket

In this article, we’ll take a look at Hello World in Racket!

How to Implement the Solution

Alright, let’s go ahead and dig into our implementation of Hello World in Racket:

#lang racket/base
"Hello, World!"

Up first, we have this peculiar line that looks kind of like a comment in Python or an import in C. As it turns out, the lang line specifies the language used by the interpreter. In fact, I already mentioned that there’s a module which provides syntax for static typing in Racket.

In this case, the language we have chosen is racket/base. This only provides us the core Racket functionality. As an alternative, we could have easily specified racket alone.

Finally, we have our print line. To be honest, we could have used the print functionality:

#lang racket/base
(print "Hello, World!)

However, I wanted to show that you can implement Hello World without the mess of parentheses. That’s because Racket automatically prints constants. If we had a slightly more complicated expression:

#lang racket
+ 2 2

We would see the three constants returned to us in their stack order:

#<procedure:+>
2
2

We would need parentheses to actually evaluate this expression1.

How to Run the Solution

At any rate, I think we’re done here. If we want to try to run the solution, we can plug some of this code into an online Racket interpreter.

Alternatively, we can download the latest version of Racket and get a copy of the solution. Assuming Racket is now in the path, we can just run the following to execute Hello World in Racket:

racket hello-world.rkt

And, that’s it. If successful, the “Hello, World!” string should print to the console1.


References

  1. J. Grifski, “Hello World in Racket,” The Renegade Coder, 05-Apr-2018. [Online]. Available: https://therenegadecoder.com/code/hello-world-in-racket/. [Accessed: 29-May-2019].  2