Red [Title: "Hello World in Red"] print "Hello, World!"
Hello World in Red was written by:
This article was written by:
If you see anything you'd like to change or update, please consider contributing.
Let's get right to our implementation of Hello World in Red.
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
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.
Now, drop both of those files in the same folder and run the following:
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.