Hello World in Scheme

Hello World in Scheme Featured Image

After learning a bit more about Lisp, I decided to dig into functional programming. Next up on the list is Hello World in Scheme, a minimalist dialect of Lisp.

Table of Contents

Scheme Background

Once again, I took to Wikipedia to learn more about the new languageOpens in a new tab..

According to Wikipedia, Scheme is the minimalist branch of Lisp. The only indicator of minimalism in Scheme I can find is the fact that it features only 23 s-expressions. Unfortunately, I wasn’t able to find any additional information on what makes scheme so simple. Let me know in the comments.

In terms of features, Scheme leverages lambda calculus, lexical scoping, tail recursion, and first-class continuations. To be honest, I had to research lexical scopingOpens in a new tab.. Turns out, lexical scoping is just a fancy name for static scoping. In other words, variables only exist within the block of text that they’re defined. In contrast, Common Lisp supports both lexical and dynamic scopingOpens in a new tab..

Despite Scheme appearing back in 1970, it’s still used today for primarily educational purposes. For instance, many universities use Scheme in their introductory programming courses. Beyond education, Scheme is mainly used by hobbyists for scripting purposes.

Hello World in Scheme

At long last, here’s an implementation of Hello World in Scheme:

(display "Hello, World!")

If you checked out the tutorial on Hello World in Lisp, then this should be easy. First things first, we have the display function. The display function works exactly as you would expect. It takes some input and displays it to the user.

As a result, it’s natural to expect that the input in this case is Hello World. All we do is pass the Hello World string to display, and we’re done.

How to Run the Solution

As usual, we can give it a go with an online Scheme interpreterOpens in a new tab.. Just drop the code above into the editor and hit run.

Alternatively, we can download CHICKEN SchemeOpens in a new tab. and a copy of the solutionOpens in a new tab.. Assuming CHICKEN Scheme is on our path, we can run the following from a command line:

csi -s hello-world.scm

That will run the Scheme file as a script which will quickly print the “Hello, World!” string.

Sample Programs in Every Language

And, that’s it! We’re all done with Hello World in Scheme.

Since we’re on the topic of Scheme, I’m actually interested in learning a bit about Racket. So, I think we’ll tackle Hello World in Racket next. Who knows what we’ll cover after that, but I want to try a few more functional languages before we move on. After all, we have time; we’re covering Hello World in Every Language!

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts