Category:ALGOL 68: Difference between revisions
m (Link project Icon to sourceforge projext page.) |
(→Coding style of samples: tweak) |
||
(54 intermediate revisions by 5 users not shown) | |||
Line 2: | Line 2: | ||
{{language|ALGOL 68 |
{{language|ALGOL 68 |
||
|parampass=both |
|parampass=both |
||
|strength= |
|strength=strong |
||
|safety=safe |
|safety=safe |
||
|express=explicit |
|express=explicit |
||
|compat=structural |
|compat=structural |
||
|checking=both |
|checking=both |
||
|tags=algol68 |
|||
|LCT=yes}} |
|LCT=yes}} |
||
ALGOL 68 (short for ALGOrithmic Language 1968) is an [[imperative programming|imperative]] computer programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics. |
ALGOL 68 (short for ALGOrithmic Language 1968) is an [[imperative programming|imperative]] computer programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics. |
||
Line 20: | Line 21: | ||
#* Loop optimization, |
#* Loop optimization, |
||
#* Representations - in minimal & larger character sets. |
#* Representations - in minimal & larger character sets. |
||
<br><br> |
|||
==Execute an ALGOL 68 program online== |
|||
* http://www.compileonline.com/execute_algol_online.php |
|||
* Algol 68G is available as one of the languages at https://tio.run |
|||
==Tasks not implemented in ALGOL 68== |
|||
==Resources== |
|||
[[Tasks not implemented in ALGOL 68]] |
|||
* ALGOL BULLETIN - March 1959 to August 1988, in 52 issues[http://archive.computerhistory.org/resources/text/algol/algol_bulletin/] |
|||
* Algol68 mailinglist - December 2008 - algol68-user AT lists.sourceforge.net[https://lists.sourceforge.net/lists/listinfo/algol68-user] |
|||
==Grammar== |
|||
FYI: There are two online manual pages: |
|||
The formal definition of Algol 68 is given by a "Two-Level" or [[wp:Van Wijngaarden grammar|"Van Wijngaarden" grammar]]. |
|||
* [https://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/a68g-doc.pdf/download Algol 68G Manual - By Marcel van der Veer] |
|||
This specifies much more than "just" the syntax and includes such semantic details as the requirement of identifiers to be declared, the necessary type checking and coercions to be applied, etc. The degree of precision allowed by the grammar came at the cost of increased complexity relative to Backus Naur Form, which was used to define [[ALGOL 60]]. It is recomended that less formal material (such as the books mentioned under "Resources" below) be consulted before delving into the Revised Report. |
|||
* [https://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/pame.pdf/download Programming Algol 68 Made Easy - Sian Leitch] |
|||
<br> |
|||
<br> |
|||
A syntax chart is available [http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised-SyntaxOnly.pdf/view here] |
|||
==Resources== |
|||
* [http://archive.computerhistory.org/resources/text/algol/algol_bulletin ALGOL BULLETIN] - March 1959 to August 1988, in 52 issues |
|||
* [https://lists.sourceforge.net/lists/listinfo/algol68-user Algol68 mailinglist] - December 2008 - algol68-user AT lists.sourceforge.net |
|||
* [http://www.linkedin.com/groups/Algol68-2333923 Algol68 group at linkedin] - includes various famous compiler composers. |
|||
<br> |
|||
'''Books available online''': |
|||
* [http://jmvdveer.home.xs4all.nl/en.algol-68-genie.html Algol 68G Manual - By Marcel van der Veer] Includes the Revised Report |
|||
* [http://www.softwarepreservation.org/projects/ALGOL/book/pame.2008.a4.pdf/view Programming Algol 68 Made Easy - by Sian Mountbatten (on softwarepreservation.org)] |
|||
* [http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised.pdf/view Informal Introduction to Algol 68 - by C. H. Lindsey & S. V. Van der Meulen (on softwarepreservation.org)] - if you prefer (and find) a hardcopy, be sure to get the 1977 edition. Highly recomended! |
|||
<br> |
|||
Or - if you prefer a hardcopy - you can try and pick up a hard cover manual like "''Informal Introduction to Algol 68''" - by C. H. Lindsey & S. V. Vander Meulen. Be sure to get the 1977 edition: |
|||
'''Editor modes''': |
|||
* [http://www.amazon.com/gp/offer-listing/0720405041/ref=dp_olp_used?ie=UTF8&condition=used www.amazon.com] - Aboout $119 |
|||
* [http://www.jemarch.net/a68-mode.el Emacs mode] for Algol 68 supporting syntax highlighting and context-sensitive indentation. |
|||
* [http://search.barnesandnoble.com/Informal-Introduction-to-ALGOL-68/C-H-Lindsey/e/9780720407266/?itm=3&USRI=Informal+Introduction+to+Algol+68 barnesandnoble.com] - about $40 |
|||
* [http://www.vim.org/scripts/script.php?script_id=1927 Vim script] providing support for syntax highlighting. |
|||
IItA68 is a beautiful book, and makes great "bedtime" reading... Highly recommended! |
|||
* [http://qbnz.com/highlighter/demo.php GeSHi syntax highlighting] |
|||
* [https://marketplace.visualstudio.com/items?itemName=jlguenego.algol68 VS-Code Algol 68 syntax highlighting] |
|||
==Status== |
==Status== |
||
Line 42: | Line 61: | ||
* 20th December 2009 - Happy 51st/41st Birthdays with [[Hamming_numbers#ALGOL_68|Hamming numbers]] - the 200th '''ALGOL 68''' code contribution on rosettacode.org! |
* 20th December 2009 - Happy 51st/41st Birthdays with [[Hamming_numbers#ALGOL_68|Hamming numbers]] - the 200th '''ALGOL 68''' code contribution on rosettacode.org! |
||
** This time code was by [[User:Algol68g|Marcel van der Veer]], author of [http://www.xs4all.nl/~jmvdveer/algol.html Algol 68 Genie] |
** This time code was by [[User:Algol68g|Marcel van der Veer]], author of [http://www.xs4all.nl/~jmvdveer/algol.html Algol 68 Genie] |
||
* 25th October 2011 - [[User:Jejones3141|Jejones3141]] added [[Soundex#ALGOL_68|Soundex]] - the 300th '''ALGOL 68''' code specimen. |
|||
== Revisions == |
== Revisions == |
||
Line 48: | Line 68: | ||
*Dec. 1968: Report on the Algorithmic Language ALGOL 68 - Offprint from Numerische Mathematik, 14, 79-218 (1969); Springer-Verlag. - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster. |
*Dec. 1968: Report on the Algorithmic Language ALGOL 68 - Offprint from Numerische Mathematik, 14, 79-218 (1969); Springer-Verlag. - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster. |
||
*Sep 1973: Revised Report on the Algorithmic Language Algol 68 - Springer-Verlag 1976 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck, C.H.A. Koster, M. Sintzoff, C.H. Lindsey, L.G.L.T. Meertens and R.G. Fisker. |
*Sep 1973: Revised Report on the Algorithmic Language Algol 68 - Springer-Verlag 1976 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck, C.H.A. Koster, M. Sintzoff, C.H. Lindsey, L.G.L.T. Meertens and R.G. Fisker. |
||
== |
==Coding style of samples, alphabets and stropping== |
||
Click "Expand" for more details. |
|||
Most of the code samples provided here have a leading <code>main:(</code> and a matching <code>)</code> at the end. These are not actually required in the language, but are included so as to highlight that the code sample is complete, and works with (at least) [[ALGOL 68G]] unmodified. |
|||
<div class="mw-collapsible mw-collapsed" style="width:880px; overflow:auto; background-color:parent;"> |
|||
<div class="mw-collapsible-content" style="padding-left:2em;"> |
|||
Many of the code samples provided here have a leading <code>main:(</code> and a matching <code>)</code> at the end. These are not actually required in the language, but are included so as to highlight the main routine. |
|||
On some compilers, it may be necessary to include appropriate "job cards" |
On some compilers, it may be necessary to include appropriate "job cards" |
||
or |
or preludes in order for the programs to compile successfully. Hopefully |
||
not too much else is required. Examples: |
not too much else is required. Examples: |
||
{|border="1" style="border-collapse: collapse; border: 5px double grey;" align="center" |
{|border="1" style="border-collapse: collapse; border: 5px double grey;" align="center" |
||
Line 73: | Line 97: | ||
FINISH |
FINISH |
||
|} |
|} |
||
<br><br>'''Alphabets''' |
|||
===Example of different program representations=== |
|||
<br><br> |
|||
Notionally, Algol 68 source is written in two alphabets. The reserved words, mode indicants (type names) and operators that are non-symbolic (.e.g. '''and''', '''or''', ...) are generally referred to as "bold words" and usually shown in a bold font in literature. Words that are identifiers (used for "variable" names, procedure names, structure member names, ...) are in a separate, non-bold font.<br> |
|||
The [https://www.softwarepreservation.org/projects/ALGOL/manual/a68s.txt/view Manual for CMU ALGOL 68S (on softwarepreservation.org)] refers to the non-bold words as being in timid face. |
|||
<br><br>'''Examples of different program representations''' |
|||
<br><br> |
|||
At the time when ALGOL 68 was defined some predominant computers had |
At the time when ALGOL 68 was defined some predominant computers had |
||
36 bit words, |
24 or 36 bit words, with 6 bit character sets. Hence it was desirable that |
||
ALGOL 68 should be able to run on machines with only uppercase. |
ALGOL 68 should be able to run on machines with only uppercase. |
||
As multiple fonts were generally unavailable, a method of identifying the bold words was required.<br> |
|||
the official spec provided for different representations of the same |
|||
The official spec provided for different representations of the same |
|||
program. Example: |
|||
program. |
|||
{|border="1" style="border-collapse: collapse; border: 5px double grey;" align="center" |
|||
Quote stropping (enclosing the bold words in single quotes) |
|||
and Point stropping (preceeding the bold words with a dot) |
|||
were used.<br> |
|||
A variant of Point stropping called RES stropping was also defined. |
|||
In RES stropping some language-defined bold words are not preceded by a dot.<br> |
|||
A pragmatic comment may have been required to indicate which |
|||
stropping convention was to be used, as in some of the examples below.<br> |
|||
Upper stropping (representing the bold words by upper case and |
|||
non-bold words in lower case) was introduced by Algol 68R.<br> |
|||
Upper stropping is used by Algol 68RS and is one of the options for Algol 68G.<br> |
|||
Rutgers ALGOL 68 uses quote stropping.<br> |
|||
Most of the samples on Rosetta Code use Upper stropping.<br><br> |
|||
Examples (pragmatic comments to set the stropping regime not shown): |
|||
{|border="1" style="border-collapse: collapse; border: 2px double grey;" align="left" |
|||
|| Algol68 as typically published |
|| Algol68 as typically published |
||
¢ bold/underline typeface ¢ |
|||
'''mode''' '''xint''' = '''int'''; |
'''mode''' '''xint''' = '''int'''; |
||
'''xint''' sum sq:=0; |
'''xint''' sum sq:=0; |
||
Line 89: | Line 131: | ||
sum sq+:=i↑2 |
sum sq+:=i↑2 |
||
'''od''' |
'''od''' |
||
|| |
|| QUOTE stropping (similar to wiki) |
||
'pr' quote 'pr' |
|||
'mode' 'xint' = 'int'; |
'mode' 'xint' = 'int'; |
||
'xint' sum sq:=0; |
'xint' sum sq:=0; |
||
Line 98: | Line 139: | ||
sum sq+:=i↑2 |
sum sq+:=i↑2 |
||
'od' |
'od' |
||
|| POINT stropping |
|||
|| Code for a 7-bit/ascii compiler |
|||
.PR UPPER .PR |
|||
MODE XINT = INT; |
|||
XINT sum sq:=0; |
|||
FOR i WHILE |
|||
sum sq/=70*70 |
|||
DO |
|||
sum sq+:=i**2 |
|||
OD |
|||
|| Code for a 6-bits/byte compiler |
|||
.PR POINT .PR |
|||
.MODE .XINT = .INT; |
.MODE .XINT = .INT; |
||
.XINT SUM SQ:=0; |
.XINT SUM SQ:=0; |
||
Line 116: | Line 147: | ||
SUM SQ .PLUSAB I .UP 2 |
SUM SQ .PLUSAB I .UP 2 |
||
.OD |
.OD |
||
|| |
|| RES stropping |
||
.PR RES .PR |
|||
mode .xint = int; |
mode .xint = int; |
||
.xint sum sq:=0; |
.xint sum sq:=0; |
||
Line 125: | Line 155: | ||
sum sq+:=i↑2 |
sum sq+:=i↑2 |
||
od |
od |
||
|| Upper stropping |
|||
MODE XINT = INT; |
|||
XINT sum sq:=0; |
|||
FOR i WHILE |
|||
sum sq /= 70*70 |
|||
DO |
|||
sum sq PLUSAB i UP 2 |
|||
OD |
|||
|} |
|} |
||
</div></div> |
|||
== Coercion (casting) == |
== Coercion (casting) == |
||
ALGOL 68 has a hierarchy of contexts which determine which kind of |
ALGOL 68 has a hierarchy of contexts which determine which kind of coercions are available at a particular point in the program. |
||
<br> |
|||
coercions are available at a particular point in the program. These contexts are: |
|||
Click "Expand" for more details. |
|||
* soft - deproceduring |
|||
<div class="mw-collapsible mw-collapsed" style="width:880px; overflow:auto; background-color:parent;"> |
|||
* weak - dereferencing or deproceduring, yielding a name |
|||
<div class="mw-collapsible-content" style="padding-left:2em;"> |
|||
* meek - dereferencing or deproceduring |
|||
* firm - meek, followed by uniting |
|||
These contexts are: |
|||
* strong - firm, followed by widening, rowing or voiding |
|||
{|class="wikitable" |
|||
!rowspan=2| N<br> |
|||
a<br> |
|||
m<br> |
|||
e |
|||
!rowspan=2| Context location |
|||
!colspan=5| Coercions available in this context |
|||
!rowspan=2| Coercion examples |
|||
|- |
|||
|bgcolor=aaaaff|Soft |
|||
|bgcolor=aaeeaa|Weak |
|||
|bgcolor=ffee99|Meek |
|||
|bgcolor=ffcc99|Firm |
|||
|bgcolor=ffcccc|Strong |
|||
|- |
|||
!S<br> |
|||
t<br> |
|||
r<br> |
|||
o<br> |
|||
n<br> |
|||
g |
|||
||Right hand side of: |
|||
* Identity-declarations, as "~" in: <syntaxhighlight algol68>REAL x = ~</syntaxhighlight> |
|||
* Initialisations, as "~" in: <syntaxhighlight algol68>REAL x := ~</syntaxhighlight> |
|||
Also: |
|||
* Actual-parameters of calls, as "~" in:<syntaxhighlight algol68>PROC: sin(~)</syntaxhighlight> |
|||
* Enclosed clauses of casts, as "~" in: <syntaxhighlight algol68>REAL(~)</syntaxhighlight> |
|||
* Units of routine-texts |
|||
* Statements yielding VOID |
|||
* All parts (but one) of a balanced clause |
|||
* One side of an identity relation, as "~" in: <syntaxhighlight algol68> ~ IS ~</syntaxhighlight> |
|||
|bgcolor=aaaaff rowspan=4 width="50px"| deproc- eduring |
|||
|bgcolor=aaeeaa rowspan=3 width="50px"| all '''soft''' then weak deref- erencing |
|||
|bgcolor=ffee99 rowspan=2 width="50px"| all '''weak''' then deref- erencing |
|||
|bgcolor=ffcc99 rowspan=1 width="50px"| all '''meek''' then uniting |
|||
|bgcolor=ffcccc width="50px"| all '''firm''' then widening, rowing and voiding |
|||
|colspan=1 bgcolor=ffcccc| |
|||
Widening occurs if there is no loss of precision. For example: An INT will be coerced to a REAL, and a REAL will be coerced to a LONG REAL. But not vice-versa. Examples: |
|||
<syntaxhighlight algol68>INT to LONG INT |
|||
INT to REAL |
|||
REAL to COMPL |
|||
BITS to []BOOL |
|||
BYTES to STRING</syntaxhighlight> |
|||
A variable can also be coerced (rowed) to an array of length 1. |
|||
For example: |
|||
<syntaxhighlight algol68>INT to [1]INT |
|||
REAL to [1]REAL</syntaxhighlight> etc |
|||
|- |
|||
!F<br> |
|||
i<br> |
|||
r<br> |
|||
m |
|||
|| |
|||
*Operands of formulas as "~" in:<syntaxhighlight algol68>OP: ~ * ~</syntaxhighlight> |
|||
*Parameters of transput calls |
|||
|colspan=3 bgcolor=ffcc99| Example: |
|||
<syntaxhighlight algol68>UNION(INT,REAL) var := 1</syntaxhighlight> |
|||
|- |
|||
!M<br> |
|||
e<br> |
|||
e<br> |
|||
k |
|||
|| |
|||
* Trimscripts (yielding INT) |
|||
* Enquiries: e.g. as "~" in the following |
|||
<syntaxhighlight algol68>IF ~ THEN ... FI</syntaxhighlight> and |
|||
<syntaxhighlight algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</syntaxhighlight> |
|||
* Primaries of calls (e.g. sin in sin(x)) |
|||
|colspan=4 bgcolor=ffee99|Examples: |
|||
<syntaxhighlight algol68>REF REF BOOL to BOOL |
|||
REF REF REF INT to INT</syntaxhighlight> |
|||
|- |
|||
!W<br> |
|||
e<br> |
|||
a<br> |
|||
k |
|||
|| |
|||
* Primaries of slices, as in "~" in: <syntaxhighlight algol68>~[1:99]</syntaxhighlight> |
|||
* Secondaries of selections, as "~" in: <syntaxhighlight algol68>value OF ~</syntaxhighlight> |
|||
|colspan=5 bgcolor=aaeeaa|Examples: |
|||
<syntaxhighlight algol68>REF BOOL to REF BOOL |
|||
REF REF INT to REF INT |
|||
REF REF REF REAL to REF REAL |
|||
REF REF REF REF STRUCT to REF STRUCT</syntaxhighlight> |
|||
|- |
|||
!S<br> |
|||
o<br> |
|||
f<br> |
|||
t |
|||
|| The LHS of assignments, as "~" in: <syntaxhighlight algol68>~ := ...</syntaxhighlight> |
|||
|colspan=6 bgcolor=aaaaff| Example: |
|||
* deproceduring of: <syntaxhighlight algol68>PROC REAL random: e.g. random</syntaxhighlight> |
|||
|} |
|||
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]]. |
|||
</div></div> |
|||
==See also== |
|||
*[[Web 68]] |
|||
*[[ALGOL 60]] |
|||
*[[ALGOL W]] |
|||
<br> |
|||
* [[Action!]] |
|||
* [[Agena]] |
|||
* [[Draco]] |
|||
* [https://en.wikipedia.org/wiki/S3_(programming_language) S3 for ICL 2900] |
|||
== Library code used in Rosetta Code samples == |
|||
[https://rosettacode.org/wiki/ALGOL_68/prelude Various (including the standard prelude)]<br/> |
|||
[https://rosettacode.org/wiki/Category:ALGOL_68-primes Prime related]<br/> |
|||
[https://rosettacode.org/wiki/Category:ALGOL_68-rows Row (array) related]<br/> |
|||
[https://rosettacode.org/wiki/Category:ALGOL_68-l-system L-System related] |
|||
== Tools == |
|||
[[Syntax_highlighting_using_Mediawiki_formatting#ALGOL 68|Format an upper-stropped Algol 68 source with Mediawiki markup]]<br/> |
|||
[[Compiler/Simple_file_inclusion_pre_processor#ALGOL 68|Implement ''read'' and ''include'' pragmatic-comments for compilers that don't support file inclusion]] |
|||
Depending on the context a MODE (type) will be coerced (widened) to another type if there is no loss |
|||
of precision. For example: An INT will be coerced to a REAL, and a REAL will be |
|||
coerced to a LONG REAL. But not vice-versa. Examples: |
|||
* INT to REAL |
|||
* REAL to COMPL |
|||
* BITS to []BOOL |
|||
* BYTES to STRING |
|||
A variable can also be coerced (rowed) to an array of length 1. For example: |
|||
* INT to [1]INT |
|||
* REAL to [1]REAL etc |
|||
Pointers are followed (dereferenced), For example: |
|||
* REF REF REAL to REAL |
|||
== Code Specimen == |
|||
{{language programming paradigm|Concurrent}} |
{{language programming paradigm|Concurrent}} |
||
{{language programming paradigm|Imperative}} |
{{language programming paradigm|Imperative}} |
Latest revision as of 20:49, 20 April 2024
![Language](http://static.miraheze.org/rosettacodewiki/thumb/2/2c/Algol68.png/64px-Algol68.png)
![Language](http://static.miraheze.org/rosettacodewiki/thumb/2/27/Rcode-button-language-crushed.png/64px-Rcode-button-language-crushed.png)
This programming language may be used to instruct a computer to perform a task.
Parameter passing methods: | By reference, By value |
---|---|
Type safety: | Safe |
Type strength: | Strong |
Type compatibility: | Structural |
Type expression: | Explicit |
Type checking: | Dynamic, Static |
Lang tag(s): | algol68 |
See Also: |
ALGOL 68 (short for ALGOrithmic Language 1968) is an imperative computer programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics.
The main aims and principles of design of ALGOL 68:
- Completeness and clarity of design,
- Orthogonal design,
- Security,
- Efficiency:
- Static mode checking,
- Mode-independent parsing,
- Independent compilation,
- Loop optimization,
- Representations - in minimal & larger character sets.
Execute an ALGOL 68 program online
- http://www.compileonline.com/execute_algol_online.php
- Algol 68G is available as one of the languages at https://tio.run
Tasks not implemented in ALGOL 68
Tasks not implemented in ALGOL 68
Grammar
The formal definition of Algol 68 is given by a "Two-Level" or "Van Wijngaarden" grammar.
This specifies much more than "just" the syntax and includes such semantic details as the requirement of identifiers to be declared, the necessary type checking and coercions to be applied, etc. The degree of precision allowed by the grammar came at the cost of increased complexity relative to Backus Naur Form, which was used to define ALGOL 60. It is recomended that less formal material (such as the books mentioned under "Resources" below) be consulted before delving into the Revised Report.
A syntax chart is available here
Resources
- ALGOL BULLETIN - March 1959 to August 1988, in 52 issues
- Algol68 mailinglist - December 2008 - algol68-user AT lists.sourceforge.net
- Algol68 group at linkedin - includes various famous compiler composers.
Books available online:
- Algol 68G Manual - By Marcel van der Veer Includes the Revised Report
- Programming Algol 68 Made Easy - by Sian Mountbatten (on softwarepreservation.org)
- Informal Introduction to Algol 68 - by C. H. Lindsey & S. V. Van der Meulen (on softwarepreservation.org) - if you prefer (and find) a hardcopy, be sure to get the 1977 edition. Highly recomended!
Editor modes:
- Emacs mode for Algol 68 supporting syntax highlighting and context-sensitive indentation.
- Vim script providing support for syntax highlighting.
- GeSHi syntax highlighting
- VS-Code Algol 68 syntax highlighting
Status
- 20th December 1968 - ALGOL 68's Final Report was ratified by UNESCO's IFIP working group 2.1 in Munich.
- 20th December 2008 - Zig Zag - the 100th ALGOL 68 code contribution on rosettacode.org!
- Happy 40th Birthday ALGOL 68,
- AND 50th Birthday ALGOL 58.
- 23rd August 2009 - algol68g-1.18.0-9h released
- 20th December 2009 - Happy 51st/41st Birthdays with Hamming numbers - the 200th ALGOL 68 code contribution on rosettacode.org!
- This time code was by Marcel van der Veer, author of Algol 68 Genie
- 25th October 2011 - Jejones3141 added Soundex - the 300th ALGOL 68 code specimen.
Revisions
- Mar. 1968: Draft Report on the Algorithmic Language ALGOL 68 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
- Oct. 1968: Penultimate Draft Report on the Algorithmic Language ALGOL 68 - Chapters 1-9 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
- Dec. 1968: Report on the Algorithmic Language ALGOL 68 - Offprint from Numerische Mathematik, 14, 79-218 (1969); Springer-Verlag. - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
- Sep 1973: Revised Report on the Algorithmic Language Algol 68 - Springer-Verlag 1976 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck, C.H.A. Koster, M. Sintzoff, C.H. Lindsey, L.G.L.T. Meertens and R.G. Fisker.
Coding style of samples, alphabets and stropping
Click "Expand" for more details.
Many of the code samples provided here have a leading main:(
and a matching )
at the end. These are not actually required in the language, but are included so as to highlight the main routine.
On some compilers, it may be necessary to include appropriate "job cards" or preludes in order for the programs to compile successfully. Hopefully not too much else is required. Examples:
Brief Algol68 | Algol68 as in rosettacode | Actual ELLA Algol 68RS code |
print(("Hello, world!",new line)) |
main:( print(("Hello, world!",new line)) ) |
PROGRAM helloworld CONTEXT VOID USE standard BEGIN print(("Hello, world!", new line)) END FINISH |
Alphabets
Notionally, Algol 68 source is written in two alphabets. The reserved words, mode indicants (type names) and operators that are non-symbolic (.e.g. and, or, ...) are generally referred to as "bold words" and usually shown in a bold font in literature. Words that are identifiers (used for "variable" names, procedure names, structure member names, ...) are in a separate, non-bold font.
The Manual for CMU ALGOL 68S (on softwarepreservation.org) refers to the non-bold words as being in timid face.
Examples of different program representations
At the time when ALGOL 68 was defined some predominant computers had
24 or 36 bit words, with 6 bit character sets. Hence it was desirable that
ALGOL 68 should be able to run on machines with only uppercase.
As multiple fonts were generally unavailable, a method of identifying the bold words was required.
The official spec provided for different representations of the same
program.
Quote stropping (enclosing the bold words in single quotes)
and Point stropping (preceeding the bold words with a dot)
were used.
A variant of Point stropping called RES stropping was also defined.
In RES stropping some language-defined bold words are not preceded by a dot.
A pragmatic comment may have been required to indicate which
stropping convention was to be used, as in some of the examples below.
Upper stropping (representing the bold words by upper case and
non-bold words in lower case) was introduced by Algol 68R.
Upper stropping is used by Algol 68RS and is one of the options for Algol 68G.
Rutgers ALGOL 68 uses quote stropping.
Most of the samples on Rosetta Code use Upper stropping.
Examples (pragmatic comments to set the stropping regime not shown):
Algol68 as typically published
mode xint = int; xint sum sq:=0; for i while sum sq≠70×70 do sum sq+:=i↑2 od |
QUOTE stropping (similar to wiki)
'mode' 'xint' = 'int'; 'xint' sum sq:=0; 'for' i 'while' sum sq≠70×70 'do' sum sq+:=i↑2 'od' |
POINT stropping
.MODE .XINT = .INT; .XINT SUM SQ:=0; .FOR I .WHILE SUM SQ .NE 70*70 .DO SUM SQ .PLUSAB I .UP 2 .OD |
RES stropping
mode .xint = int; .xint sum sq:=0; for i while sum sq≠70×70 do sum sq+:=i↑2 od |
Upper stropping
MODE XINT = INT; XINT sum sq:=0; FOR i WHILE sum sq /= 70*70 DO sum sq PLUSAB i UP 2 OD |
Coercion (casting)
ALGOL 68 has a hierarchy of contexts which determine which kind of coercions are available at a particular point in the program.
Click "Expand" for more details.
These contexts are:
N a |
Context location | Coercions available in this context | Coercion examples | ||||
---|---|---|---|---|---|---|---|
Soft | Weak | Meek | Firm | Strong | |||
S t |
Right hand side of:
Also:
|
deproc- eduring | all soft then weak deref- erencing | all weak then deref- erencing | all meek then uniting | all firm then widening, rowing and voiding |
Widening occurs if there is no loss of precision. For example: An INT will be coerced to a REAL, and a REAL will be coerced to a LONG REAL. But not vice-versa. Examples: INT to LONG INT
INT to REAL
REAL to COMPL
BITS to []BOOL
BYTES to STRING A variable can also be coerced (rowed) to an array of length 1. For example: INT to [1]INT
REAL to [1]REAL |
F i |
|
Example:
UNION(INT,REAL) var := 1 | |||||
M e |
IF ~ THEN ... FI FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc
|
Examples:
REF REF BOOL to BOOL
REF REF REF INT to INT | |||||
W e |
|
Examples:
REF BOOL to REF BOOL
REF REF INT to REF INT
REF REF REF REAL to REF REAL
REF REF REF REF STRUCT to REF STRUCT | |||||
S o |
The LHS of assignments, as "~" in: ~ := ... |
Example:
|
For more details about Primaries and Secondaries refer to Operator precedence.
See also
Library code used in Rosetta Code samples
Various (including the standard prelude)
Prime related
Row (array) related
L-System related
Tools
Format an upper-stropped Algol 68 source with Mediawiki markup
Implement read and include pragmatic-comments for compilers that don't support file inclusion
Subcategories
This category has the following 3 subcategories, out of 3 total.
@
- ALGOL 68 Implementations (9 P)
- ALGOL 68 User (8 P)
Pages in category "ALGOL 68"
The following 200 pages are in this category, out of 1,020 total.
(previous page) (next page)H
I
- I before E except after C
- Iccanobif primes
- Identity matrix
- Idiomatically determine all the characters that can be used for symbols
- Idiomatically determine all the lowercase and uppercase letters
- Idoneal numbers
- Implicit type conversion
- Include a file
- Inconsummate numbers in base 10
- Increasing gaps between consecutive Niven numbers
- Increment a numerical string
- Infinity
- Inner classes
- Input loop
- Input/Output for lines of text
- Input/Output for pairs of numbers
- Integer comparison
- Integer overflow
- Integer sequence
- Intersecting number wheels
- Introspection
- Inventory sequence
- Inverted syntax
- ISBN13 check digit
- Isograms and heterograms
- Isqrt (integer square root) of X
- Iterated digits squaring
J
K
L
- L-system
- Lah numbers
- Langton's ant
- Largest difference between adjacent primes
- Largest five adjacent number
- Largest int from concatenated ints
- Largest number divisible by its digits
- Largest palindrome product
- Largest prime factor
- Largest product in a grid
- Largest proper divisor of n
- Last Friday of each month
- Last list item
- Law of cosines - triples
- Leap year
- Least common multiple
- Least m such that n! + m is prime
- Left factorials
- Length of an arc between two angles
- Leonardo numbers
- Letter frequency
- Levenshtein distance
- Linear congruential generator
- List comprehensions
- Literals/Floating point
- Literals/Integer
- Literals/String
- Logical operations
- Long multiplication
- Long primes
- Long year
- Longest common prefix
- Longest common subsequence
- Longest common substring
- Longest common suffix
- Longest palindromic substrings
- Longest string challenge
- Look-and-say sequence
- Loop over multiple arrays simultaneously
- Loops/Break
- Loops/Continue
- Loops/Do-while
- Loops/Downward for
- Loops/For
- Loops/For with a specified step
- Loops/Foreach
- Loops/Increment loop index within loop body
- Loops/Infinite
- Loops/N plus one half
- Loops/Nested
- Loops/While
- Loops/With multiple ranges
- Loops/Wrong ranges
- Lucas-Lehmer test
- Ludic numbers
- Luhn test of credit card numbers
- Lychrel numbers
M
- Mad Libs
- Magic 8-ball
- Magic constant
- Magic numbers
- Magic squares of doubly even order
- Magic squares of odd order
- Magic squares of singly even order
- Magnanimous numbers
- Man or boy test
- Mandelbrot set
- Map range
- Matrix multiplication
- Matrix transposition
- Matrix with two diagonals
- Matrix-exponentiation operator
- Maximum difference between adjacent elements of list
- Maximum triangle path sum
- McNuggets problem
- MD5
- Meissel–Mertens constant
- Memory allocation
- Memory layout of a data structure
- Menu
- Mersenne primes
- Mertens function
- Metaprogramming
- Metered concurrency
- Mian-Chowla sequence
- Middle three digits
- Miller–Rabin primality test
- Minimum multiple of m where digital sum equals m
- Minimum number of cells after, before, above and below NxN squares
- Minimum numbers of three lists
- Minimum positive multiple in base 10 using only 0 and 1
- Minimum primes
- Modified random distribution
- Modular arithmetic
- Modular exponentiation
- Modular inverse
- Monads/Maybe monad
- Monads/Writer monad
- Monte Carlo methods
- Monty Hall problem
- Mosaic matrix
- Motzkin numbers
- Move-to-front algorithm
- Multi-dimensional array
- Multifactorial
- Multiple distinct objects
- Multiple regression
- Multiplication tables
- Multiplicative order
- Multiplicatively perfect numbers
- Multisplit
- Munchausen numbers
- Mutual recursion
- Möbius function
N
- N'th
- N-body problem
- N-grams
- N-queens problem
- Named parameters
- Naming conventions
- Narcissist
- Narcissistic decimal number
- Native shebang
- Negative base numbers
- Neighbour primes
- Nested function
- Next highest int from digits
- Nice primes
- Nim game
- Non-continuous subsequences
- Non-decimal radices/Convert
- Non-decimal radices/Input
- Non-decimal radices/Output
- Non-transitive dice
- Nth root
- Null object
- Number names
- Number reversal game
- Numbers divisible by their individual digits, but not by the product of their digits.
- Numbers in base 10 that are palindromic in bases 2, 4, and 16
- Numbers in base-16 representation that cannot be written with decimal digits
- Numbers k such that the last letter of k is the same as the first letter of k+1
- Numbers which are not the sum of distinct squares
- Numbers which are the cube roots of the product of their proper divisors
- Numbers whose binary and ternary digit sums are prime
- Numbers whose count of divisors is prime