Table of Contents
ALGOL 68 Background
According to Wikipedia, ALGOL 68—also known as Algorithmic Language 68—is a successor to the ALGOL 60 language. As the name suggests, ALGOL 68 first appeared in 1968 as an imperative programming language.
That said, ALGOL 68 has a much wider scope than ALGOL 60. For instance, ALGOL 68 includes user-declared types, expression-based syntax, concurrency, and even slicing.
Of course, I think the most interesting language feature is the overwhelming list of reserved words which includes 60 different symbols. Most of these symbols I couldn’t even guess their purpose. For example, what do you think
esac does? How about
ouse? James Jones offers a great explanation down in the comments.
In general though, I find that most of the symbols are pretty typical. Many of which provide either control flow or iteration. Meanwhile, others provide typing. So, overall the language seems pretty tame. Feel free to check out the Wikipedia page for the full syntax and features list.
Hello World in ALGOL 68
Without further ado, let’s implement Hello World in ALGOL 68:
printf(($gl$, "Hello, World!"))
Now, I believe we can actually shorten this implementation to look identical to the Python implementation. But, that wouldn’t be too interesting. Instead, we opted to use a printf solution to show off a couple of features.
If you’re unfamiliar with printf, it’s typically a version of the print function which allows for string formatting. Unfortunately, that’s about where the similarities end. In ALGOL 68, the syntax for formatting text is about as bizarre as I’ve ever seen. Luckily, we have a simple example:
In this example, everything between the dollar signs is considered a format string. In this case, we have two characters: g and l.
Since we’re formatting strings, one of those tokens will be replaced by our “Hello, World!” string. In this case, it’s g. As for l, that’s actually the newline token—something we haven’t paid a lot of attention to in this series. When put together, “Hello, World!” will print to the console.
Another interesting bit about this program is the fact that we have double parentheses that almost look redundant. But make no mistake, they’re important:
1 printf($gl$, "Hello, World!") 1 a68g: error: 1: incorrect number of arguments for PROC ( "SIMPLOUT") VOID (detected in particular-program).
To be honest, I don’t understand the error. My best guess is printf requires an array of arguments. Whereas, the varargs solution I’m proposing issues the format string and “Hello, World!” as separate arguments. Fortunately, James Jones has a great explanation for this as well in the comments.
How to Run the Solution
Perhaps the easiest way to run the solution is to use an online ALGOL 68 editor. If we copy the solution above into the editor, we can hit execute to run it.
Alternatively, we have the option to install an ALGOL 68 interpreter. Apparently, there is a limited ALGOL 68 Genie interpreter which should get the job done. After all, it’s the same interpreter the online solution uses. Feel free to leverage the documentation.
Sample Programs in Every Language
Once again, thanks for sticking around and a special thanks to Trever Shick for giving up some of their time to help with the series.. As usual, I’ll continue my trend of focusing on the work of others for a little while. When I get some free time, I’ll catch up on the various additions I’ve made myself.
Oh, don’t forget to share this article! Every share helps get this material in front of someone who might enjoy it. You don’t want to deny them of that joy, do you?!
Until next time!