{"id":11010,"date":"2025-06-27T01:01:00","date_gmt":"2025-06-27T05:01:00","guid":{"rendered":"https:\/\/www.both.org\/?p=11010"},"modified":"2025-07-08T14:44:04","modified_gmt":"2025-07-08T18:44:04","slug":"thinking-about-algol-68","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=11010","title":{"rendered":"Thinking about Algol 68"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"11010\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">3    <\/span>\r\n<\/div><\/div>\n<p><em>In memory of J. Kevin Douglas, a good friend and fellow fan of Algol 68<\/em><\/p>\n\n\n\n<p>I took my first computer science course in my second year at the University of British Columbia in Vancouver, Canada. The course was a full year, starting in September 1974, and we programmed in Waterloo FORTRAN IV, which if memory serves was called Watfor or maybe Watfiv at the time. We also had a brief session with IBM 360 \/ 370 Assembler language. Both languages were available to us in the form of batch timeshare services where we wrote our programs on IBM 029 key punches and submitted the card decks to be run, generating printouts which were almost entirely compilation or execution failures interspersed with the occasional output of a program that generated the hoped-for results.<\/p>\n\n\n\n<p>In sum, things were pretty basic \u201cback in the day\u201d. Nevertheless I kept at it and in my next and subsequent years as an undergrad had access to interactive terminals and many other programming languages, including PL\/1, Pascal, BCPL, LISP, Algol W, APL\u2026<\/p>\n\n\n\n<p>\u2026 And Algol 68.<\/p>\n\n\n\n<p>My friend and fellow student Kevin Douglas, who was much more of a computer scientist than I will ever be, introduced me to Algol 68. There were graduate students at UBC working on Algol 68 implementations. Professor J.E.L. Peck, an Algol 68 luminary and member of <a href=\"https:\/\/www.algol68-lang.org\/docs\/algol68-revised-report.pdf\">the committee in charge of designing the language<\/a>, was head of the department.&nbsp; While my interests in computer science tended more toward numerical analysis, what I perceived as the sheer expressiveness of Algol 68 was a powerful distraction.<\/p>\n\n\n\n<p>And the language itself &#8211; said to be somewhere between extremely difficult and impossible to compile due to its innovative two level grammar, and yet at the same time astonishingly elegant for its orthogonality and resulting expressive nature &#8211; who could not fall under the charms of&nbsp; that?&nbsp; Finally, let\u2019s all face it &#8211; if the main goal of a new computer language is to make it easy to compile into machine code, then we\u2019d all still be writing in assembly language.&nbsp; Or maybe something like <a href=\"https:\/\/en.wikipedia.org\/wiki\/PL360\">PL\/360<\/a>.<\/p>\n\n\n\n<p>As it turns out, Algol 68 accomplished two main things beyond all the design and implementation efforts:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>It influenced, to some degree at least, the design of many subsequent languages and utilities, including C and the Bourne shell;<\/li>\n\n\n\n<li>It created a legion of opposing parties, who not only sat on the sidelines heckling, but in some cases, built really useful things to show that there were other ways to proceed, including the Pascal and Ada programming languages.<\/li>\n<\/ol>\n\n\n\n<p>Fast forward to 2025, and Algol 68 seems to many to be a historical oddity; a programming language that had as much negative influence as positive.&nbsp; Most people that I have run into who have even heard of Algol 68 \u201cknow\u201d that it is a complicated language full of weird theoretical ideas that have not aged well, and in the end neither of great utility nor of great interest.<\/p>\n\n\n\n<p>In my opinion and experience, Algol 68 is largely a victim of mostly misinformed &#8211; or uninformed &#8211; gossip, and the wisdom and efforts of its designers and implementers are worthy of more reasonable consideration.&nbsp; Therefore, I hope to show that this language remains relevant, interesting and even useful going on 60 years later.&nbsp; I hope to dispel some of the \u201creceived ideas\u201d around the language. And I hope to achieve this by demonstrating some simple and useful code examples that show many aspects of the language worth learning and using.<\/p>\n\n\n\n<p>What makes my quest much easier and more relevant are two fine current, maintained implementations of Algol 68 that are ready for experimentation, and in many cases, daily use.&nbsp; These are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/jmvdveer.home.xs4all.nl\/en.algol-68-genie.html\">Algol 68 Genie<\/a>, a compiler &#8211; interpreter developed and maintained by Marcel van der Veer;<\/li>\n\n\n\n<li><a href=\"https:\/\/gcc.gnu.org\/wiki\/Algol68FrontEnd\">GNU Algol 68<\/a>, a recent and ongoing project to develop a production quality compiler based on the GNU Compiler Collection tools, being developed by Jose Marchesi.<\/li>\n<\/ul>\n\n\n\n<p>Of even greater importance is that both of these excellent Algol 68 implementations are open source.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>A first example<\/strong><\/h2>\n\n\n\n<p>Let\u2019s take a look at our first simple Algol 68 program, which demonstrates a few important Algol 68 details.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u00a0 \u00a0 BEGIN\n2\u00a0 \u00a0 \u00a0 \u00a0 first random(42);\n3\u00a0 \u00a0 \u00a0 \u00a0 REAL sum of randoms := 0.0;\n4\u00a0 \u00a0 \u00a0 \u00a0 WHILE sum of randoms &lt; 10.0 DO\u00a0\n5\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 REAL r := next random;\n6\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 sum of randoms +:= r;\n7\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 print((\"random number = \",r,\"; sum = \",sum of randoms,new line))\n8\u00a0 \u00a0 \u00a0 \u00a0 OD\n9\u00a0 \u00a0 END<\/code><\/pre>\n\n\n\n<p>Line 1 &#8211; BEGIN, line 9 &#8211; END and all the stuff between form&nbsp; an Algol 68 <strong><em>closed<\/em><\/strong> <strong><em>clause<\/em><\/strong>.&nbsp; BEGIN and END serve a similar purpose to { and } in C, Java and similar languages, and to begin and end in Pascal.<\/p>\n\n\n\n<p>Clauses are an important concept in the definition of Algol 68.&nbsp; Page 53 of the Revised Report states:<\/p>\n\n\n\n<p><em>(Clauses provide<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>a hierarchical structure for programs,<\/em><\/li>\n\n\n\n<li><em>the introduction of new ranges of definitions,<\/em><\/li>\n\n\n\n<li><em>serial or collateral composition, parallelism, choices and loops.)<\/em><\/li>\n<\/ul>\n\n\n\n<p>In our program, the stuff between BEGIN and END above&nbsp; is an example of a <strong><em>serial clause<\/em><\/strong>, that is, a collection of expressions that are evaluated serially (one after another).&nbsp; BEGIN and END are written in upper case to indicate that they are pre-defined symbols known to the compiler.<\/p>\n\n\n\n<p>Line 2 calls the procedure \u201cfirst random\u201d with the argument \u201c42\u201d.&nbsp; Here we see a space between \u201cfirst\u201d and \u201crandom\u201d; this could also be written as \u201cfirstrandom\u201d, \u201cfi r stran dom\u201d or various other combinations since spaces don\u2019t matter within the names of variables, procedures and so forth.&nbsp; \u201cFirst random\u201d is a predefined procedure that initializes a random number generator based on its argument.<\/p>\n\n\n\n<p>Line 3 declares a real number variable called \u201csum of randoms\u201d and initializes it to 0.0, a real constant. Note that the assignment operator in Algol 68 is \u201c:=\u201d.&nbsp; Not seen here is the equality comparison operator, which is \u201c=\u201d.&nbsp; Contrast this to assignment in C which is \u201c=\u201d and equality comparison which is \u201c==\u201d.<\/p>\n\n\n\n<p>We will talk more about variable declarations, assignment and equality operators soon.<\/p>\n\n\n\n<p>Note also that lines 2 and 3 are separated by a semicolon, what Algol 68 calls a <strong><em>go on symbol<\/em><\/strong>.&nbsp; Algol 68 thinks of semicolons as separators, not terminators (as in C).<\/p>\n\n\n\n<p>Line 4 is the start of a <strong><em>loop clause<\/em><\/strong>, ending on line 8, which encloses a collection of expressions to be evaluated repetitively and serially.&nbsp; In this case, the looping continues until the value of \u201csum of randoms\u201d is greater than or equal to 10.0.&nbsp; Note that the tag OD ends the serial clause opened by the tag DO.&nbsp; Compare this to a similar construct in C which would be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (sum_of_randoms &lt; 10.0) { \u2026 }<\/code><\/pre>\n\n\n\n<p>Line 5 declares the real number variable \u201cr\u201d which is local to the loop and assigns to it the value of the \u201cnext random\u201d procedure, being the next random number in the sequence.<\/p>\n\n\n\n<p>Line 6 increments the value of \u201csum of randoms\u201d by the value of \u201cr\u201d.&nbsp; The use of the \u201c+:=\u201d or \u201cplus and becomes\u201d operator is equivalent to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sum of randoms := sum of randoms + r<\/code><\/pre>\n\n\n\n<p>Line 7 prints the values of \u201cr\u201d and \u201csum of randoms\u201d with preceding string labels and a trailing new line character inserted into the output stream by a call to the \u201cnew line\u201d predefined procedure.<\/p>\n\n\n\n<p>Worth mentioning here are the double parentheses following \u201cprint\u201d and ending the expression.&nbsp; The outermost pair \u201c()\u201d enclose the argument to \u201cprint\u201d, while the innermost pair surround a <strong><em>collateral clause<\/em><\/strong>, in this case a list of expressions separated by commas.&nbsp; The \u201cprint\u201d procedure only accepts one argument, but that argument can be an array, or <strong><em>row<\/em><\/strong>; the collateral clause, enclosed by parentheses, is in this case a <strong><em>row display<\/em><\/strong> creating a list (Algol 68 terminology for what we might call a list).<\/p>\n\n\n\n<p>In summary, the row display<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(\"random number = \",r,\"; sum = \",sum of randoms,new line)<\/code><\/pre>\n\n\n\n<p>Is similar to a Java initializer like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{ \u201crandom number = \u201c, r, \u201c; sum = \u201c, sum_of_randoms, new_line}<\/code><\/pre>\n\n\n\n<p>The astute reader may well be wondering about an array of expressions of clearly different types like string, real and whatever new_line is.&nbsp; We will eventually discuss that!<\/p>\n\n\n\n<p>For now, I can compile and run this program using Algol 68 Genie in a Linux terminal window as follows:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-code\"><code>$ a68g a1.a68\nrandom number = +2.61736743850634e\u00a0 -1; sum = +2.61736743850634e\u00a0 -1\nrandom number = +2.44074219372123e\u00a0 -2; sum = +2.86144165787846e\u00a0 -1\nrandom number = +4.19119445839897e\u00a0 -1; sum = +7.05263611627743e\u00a0 -1\nrandom number = +4.84060694929212e\u00a0 -1; sum = +1.18932430655695e\u00a0 +0\nrandom number = +6.92153602372855e\u00a0 -1; sum = +1.88147790892981e\u00a0 +0\nrandom number = +4.53971547773108e\u00a0 -1; sum = +2.33544945670292e\u00a0 +0\nrandom number = +6.70357855502516e\u00a0 -1; sum = +3.00580731220543e\u00a0 +0\nrandom number = +8.19231704808772e\u00a0 -1; sum = +3.82503901701421e\u00a0 +0\nrandom number = +8.88931809924543e\u00a0 -1; sum = +4.71397082693875e\u00a0 +0\nrandom number = +4.38520186813548e\u00a0 -1; sum = +5.15249101375230e\u00a0 +0\nrandom number = +8.07107185712084e\u00a0 -1; sum = +5.95959819946438e\u00a0 +0\nrandom number = +9.24482085043564e\u00a0 -1; sum = +6.88408028450795e\u00a0 +0\nrandom number = +7.35386690590531e\u00a0 -1; sum = +7.61946697509848e\u00a0 +0\nrandom number = +3.30123137915507e\u00a0 -1; sum = +7.94959011301398e\u00a0 +0\nrandom number = +4.65522854821756e\u00a0 -1; sum = +8.41511296783574e\u00a0 +0\nrandom number = +9.83509750338271e\u00a0 -1; sum = +9.39862271817401e\u00a0 +0\nrandom number = +6.23938688309863e\u00a0 -1; sum = +1.00225614064839e\u00a0 +1\n$<\/code><\/pre>\n\n\n\n<p>That\u2019s it for now.&nbsp; In the next article, we\u2019ll dig into a few of the less obvious but still important details that make this all work.&nbsp; Then we can move on to see some more cool things that we can do in Algol 68.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>3 In memory of J. Kevin Douglas, a good friend and fellow fan of Algol 68 I took my first computer science course in my second year at the University of British Columbia in Vancouver, Canada. The course was a full year, starting in September 1974, and we programmed in Waterloo FORTRAN IV, which if [&hellip;]<\/p>\n","protected":false},"author":430,"featured_media":5233,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[98,158,150],"tags":[783,784],"class_list":["post-11010","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","category-open-source","category-programming","tag-algol-68","tag-computer-languages"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/11010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/430"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11010"}],"version-history":[{"count":4,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/11010\/revisions"}],"predecessor-version":[{"id":11098,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/11010\/revisions\/11098"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/5233"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}