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 page. 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 toolchain. Of course, we’ll also want to grab a copy of the Hello World script from GitHub.

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!

Series Navigation← Hello World in WrenHello World in Julia →
Advertisements

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.