Hello World in Red

Hello World in Red Featured Image

Hello and welcome again to another edition of Hello World in Every Language. Last time we played around with a newer language called Wren, and I had a lot of fun working on that article. Today, I’m looking to implement Hello World in Red, an open-source language that first appeared in 2011.

Table of Contents

Red Background

To continue the new languages trend, I decided to dig into another open-source language called Red. However, unlike Wren, Red has a Wikipedia pageOpens in a new tab.. So, that makes writing this section a lot easier.

According to Wikipedia, Red is a full stack programming language inspired by Rebol. Of course, Red was designed to eliminate many of the issues found in Rebol. For example, Red can be used on a much wider array of tasks from system programming to scripting.

In terms of features, Red offers strong metaprogramming utilities much like Racket. Naturally, these utilities allow for language dialects. For instance, Red has a language dialect called Red/System which is basically a C-level version of the language.

Another cool feature of Red is that it doesn’t depend on any third-party libraries except for the Rebol2 interpreter. Eventually, the developers plan to bootstrap Red to eliminate all dependencies.

I suppose I wouldn’t be doing Red justice if I didn’t mention that the toolchain can cross-compile to several platforms including MSDOS, WindowsXP, Linux, MacOS, and Android (list is non-exhaustive).

Also, fun fact: the entire Red toolchain is contained in a 1 MB executable. Now, that’s awesome!

Hello World in Red

Anyway, let’s get right to our implementation of Hello World in Red:

Red [Title: "Hello World in Red"]

print "Hello, World!"

Well, that’s just about it. Honestly, this is about the weirdest syntax I’ve ever seen, so I really had to dig into the docs.

According to Helpin’Red, the first line in our solution is the header, and it’s absolutely necessary for all scripts. The header is composed of two parts: the Red keyword and the block.

Now, every script will have the Red keyword. As for the block, well, that will vary per script. Honestly, the information in that block is largely optional, but it can be used to declare script information such as a title, a description, a version, and an author. In this case, I simply gave the script a title.

In addition to arbitrary information, the first block can also be used to import libraries. For example, we could have implemented Hello World in Red as a GUI:

Red [needs: 'view]

view [
  text "Hello, World!"

Here, we use the header block to import the graphics view library. Then, we use that library to display a window containing “Hello, World!”

At any rate, the last line in our original implementation clearly prints “Hello, World!” to the user. We’ve seen this plenty of times already so no need to dig into it.

How to Run the Solution

If we’re looking to run this solution, perhaps the easiest way to do so is to download the latest Red toolchainOpens in a new tab.. Of course, we’ll also want to grab a copy of the Hello World script from GitHubOpens in a new tab..

Now, drop both of those files in the same folder and run the following:

red hello-world.red

If you’re a Windows user, you may need to call the executable directly. 

In addition, we can compile our script using the following command:

red -c hello-world.red

At this point, I would usually share some online editor you could use to test code, but Red doesn’t appear to have one. If one exists, let me know in the comments.

Sample Programs in Every Language

Well, that’s it! Thanks again for sticking around on this journey. I am having a lot of fun playing with these new languages, and I plan to keep going for at least another week.

If there’s a language you’d like to see in the future, let me know in the comments. Of course, don’t forget to share this article if you enjoyed it. See you next time!

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