Hello World in ALGOL 68

Hello World in ALGOL 68 Featured Image

Welcome back to another installment in the Hello World in Every Language series. Today, we’re tackling Hello World in ALGOL 68, a language provided by one of my contributors, Trever Shick.

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: $gl$.

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!

Series Navigation← Hello World in BashHello World in Google Apps Script →
Advertisements

4 thoughts on “Hello World in ALGOL 68

  1. James Jones Reply

    Oh, about some of those keywords… Algol 68 has a convention of ending constructs with the reverse of the keyword that begins them. So if statements end with fi, the loop body that starts with do ends with od, and case is ended with esac.

    Algol 68 has elif so that chained if statements don’t creep across the page due to indentation:

    if foo then
        ....
    elif bar then
        ....
    else
        ....
    fi
    

    Also, out does for case what else does for if:

    mumble := case i of 1, 5, 3, 4, 6 out -1 esac

    So, logically, if you have elif from “else if”, you should have ouse from “out case”:

    frotz := case i of x, y, z ouse j of 0, 1, 2 out -1 esac

    • Jeremy Grifski Post authorReply

      Oh okay! That makes sense. I believe I’ve seen the if/fi syntax elsewhere. I just hadn’t put two and two together.

      Also, great explanation of ouse. I’m going to direct people to your comment from the article if you don’t mind.

      By the way, I believe you can style comments here with markdown. Just to test it, I updated your code block above.

  2. James Jones Reply

    Algol 68 doesn’t support varying numbers of arguments, so printf() takes one argument of mode (type) row (array) of “SIMPLOUT”. “SIMPLOUT” is a mode that is a union of all the basic types one can output (bool, string, char, and various lengths of int, real, compl (complex) and bits)–though it has to include format as well (in Algol 68, there’s a format type, which isn’t a string). A row value is enclosed in parentheses, hence the double parens. (Algol 68 uses characters with reckless abandon, so I don’t understand why they didn’t go with something other than parentheses for the purpose.)

    • Jeremy Grifski Post authorReply

      Good to know! I was having some trouble understanding some of the syntax of ALGOL 68. Based on the error, my best guess was that the language didn’t support a varying number of arguments. I believe Rust is similar, but Rust has support for macros which allow you to circumvent this issue.

      I’m not a fan of using parentheses to define a row and enclose a function. I think most people–even people who don’t code–would argue the syntax is bizarre. The parentheses look redundant.

      At any rate, I appreciate the explanation!

Leave a Comment

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