Hello World in Racket

Our first program will print the classic “hello world” message. Here’s the full source code.

#lang racket

(define (main)
  (displayln "hello world"))

(main)

To run the program, put the code in a file named hello-world.rkt and use the Racket interpreter to execute it.

$ racket hello-world.rkt
hello world

Sometimes we’ll want to compile our programs into bytecode files that can be executed directly. We can do this using Racket’s raco command.

First, compile the code:

$ raco exe -o hello-world hello-world.rkt
$ ls
hello-world    hello-world.rkt

We can then execute the compiled binary directly.

$ ./hello-world
hello world

Now that we can run and build basic Racket programs, let’s learn more about the language.