Category:ALGOL 68: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎Coercion (casting): clarify the difference between soft, week, meek, firm and strong typing.)
Line 144: Line 144:
coercions are available at a particular point in the program. These contexts are:
coercions are available at a particular point in the program. These contexts are:
{|class="wikitable"
{|class="wikitable"
!rowspan=2| N<br>
! Context name !! Context location !! Coercions available in this context!! Coercion examples
a<br>
m<br>
e
!rowspan=2| Context location
!colspan=5| Coercions available in this context
!rowspan=2| Coercion examples
|-
|-
|bgcolor=eeeeee|Soft
!soft
|bgcolor=dddddd|Meek
|| The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang>
|bgcolor=cccccc|Weak
|| deproceduring
|bgcolor=bbbbbb|Firm
||
|bgcolor=aaaaaa|Strong
* deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang>
|-
!weak
||
* Primaries of slices, as in "~" in: <lang algol68>~[1:99]</lang>
* Secondaries of selections, as "~" in: <lang algol68>value OF ~</lang>
|| all '''soft''' then weak dereferencing
||
<lang 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</lang>
|-
!meek
||
* Trimscripts (yielding INT)
* Enquiries: e.g. as "~" in the following<lang algol68>IF ~ THEN ... FI</lang> and <lang algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</lang>
* Primaries of calls (e.g. sin in sin(x))
|| all '''weak''' then dereferencing
||
<lang algol68>REF REF BOOL to BOOL
REF REF REF INT to INT</lang>
|-
!firm
||
*Operands of formulas as "~" in:<lang algol68>OP: ~ * ~</lang>
*Parameters of transput calls
|| all '''meek''' then uniting
|| e.g. <lang algol68>UNION(INT,REAL) var := 1</lang>
|-
|-
!S<br>
!strong
t<br>
r<br>
o<br>
n<br>
g
||Right hand side of:
||Right hand side of:
* Identity-declarations, as "~" in: <lang algol68>REAL x = ~</lang>
* Identity-declarations, as "~" in: <lang algol68>REAL x = ~</lang>
Line 191: Line 174:
* All parts (but one) of a balanced clause
* All parts (but one) of a balanced clause
* One side of an identity relation, as "~" in: <lang algol68> ~ IS ~</lang>
* One side of an identity relation, as "~" in: <lang algol68> ~ IS ~</lang>
|bgcolor=EEEEEE rowspan=4 width="50px"| deproc- eduring
|| all '''firm''' then widening, rowing and voiding
|bgcolor=DDDDDD rowspan=3 width="50px"| all '''soft''' then weak deref- erencing
||Widening occures 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:
|bgcolor=CCCCCC rowspan=2 width="50px"| all '''weak''' then deref- erencing
|bgcolor=BBBBBB rowspan=1 width="50px"| all '''meek''' then uniting
|bgcolor=AAAAAA width="50px"| all '''firm''' then widening, rowing and voiding
|colspan=1 bgcolor=AAAAAA|
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:
<lang algol68>INT to LONG INT
<lang algol68>INT to LONG INT
INT to REAL
INT to REAL
Line 198: Line 186:
BITS to []BOOL
BITS to []BOOL
BYTES to STRING</lang>
BYTES to STRING</lang>
A variable can also be coerced (rowed) to an array of length 1. For example:
A variable can also be coerced (rowed) to an array of length 1.

For example:
<lang algol68>INT to [1]INT
<lang algol68>INT to [1]INT
REAL to [1]REAL</lang> etc
REAL to [1]REAL</lang> etc
|-
!F<br>
i<br>
r<br>
m
||
*Operands of formulas as "~" in:<lang algol68>OP: ~ * ~</lang>
*Parameters of transput calls
|colspan=3 bgcolor=BBBBBB| Example:
<lang algol68>UNION(INT,REAL) var := 1</lang>
|-
!M<br>
e<br>
e<br>
k
||
* Trimscripts (yielding INT)
* Enquiries: e.g. as "~" in the following
<lang algol68>IF ~ THEN ... FI</lang> and
<lang algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</lang>
* Primaries of calls (e.g. sin in sin(x))
|colspan=4 bgcolor=CCCCCC|Examples:
<lang algol68>REF REF BOOL to BOOL
REF REF REF INT to INT</lang>
|-
!W<br>
e<br>
a<br>
k
||
* Primaries of slices, as in "~" in: <lang algol68>~[1:99]</lang>
* Secondaries of selections, as "~" in: <lang algol68>value OF ~</lang>
|colspan=5 bgcolor=DDDDDD|Examples:
<lang 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</lang>
|-
!S<br>
o<br>
f<br>
t
|| The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang>
|colspan=6 bgcolor=EEEEEE| Example:
* deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang>
|}
|}
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]].
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]].

Revision as of 06:40, 19 June 2013

Language
Language
ALGOL 68
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: Soft, weak, meek, firm and strong - depending on context.
Type compatibility: Structural
Type expression: Explicit
Type checking: Dynamic, Static
See Also:
Listed below are all of the tasks on Rosetta Code which have been solved using ALGOL 68.

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:

  1. Completeness and clarity of design,
  2. Orthogonal design,
  3. Security,
  4. Efficiency:
    • Static mode checking,
    • Mode-independent parsing,
    • Independent compilation,
    • Loop optimization,
    • Representations - in minimal & larger character sets.

Execute an ALGOL 68 program online

Grammar

The grammar for ALGOL 68 is officially in the two level, Van Wijngaarden grammar but a subset has been done in the one level Backus–Naur Form:

Resources

  • ALGOL BULLETIN - March 1959 to August 1988, in 52 issues[3]
  • Algol68 mailinglist - December 2008 - algol68-user AT lists.sourceforge.net[4]

FYI: There are two online manual pages:

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:

IItA68 is a beautiful book, and makes great "bedtime" reading... Highly recommended!

Editor modes:

  • Emacs mode for Algol 68 supporting syntax highlighting and context-sensitive indentation.
  • Vim script providing support for syntax colouring.

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!
  • 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.

Code samples

Most 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 that the code sample is complete, and works with (at least) ALGOL 68G unmodified.

On some compilers, it may be necessary to include appropriate "job cards" or precludes 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

Example of different program representations

At the time when ALGOL 68 was defined some predominant computers had 36 bit words, and 6 bit character sets. Hence it was desirable that ALGOL 68 should be able to run on machines with only uppercase. Hence the official spec provided for different representations of the same program. Example:

Algol68 as typically published
¢ bold/underline typeface ¢
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)
'pr' quote 'pr' 
'mode' 'xint' = 'int';
'xint' sum sq:=0;
'for' i 'while'
  sum sq≠70×70
'do'
  sum sq+:=i↑2
'od' 
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;
.XINT SUM SQ:=0;
.FOR I .WHILE
  SUM SQ .NE 70*70
.DO
  SUM SQ .PLUSAB I .UP 2
.OD
Algol68 using RES stropping
.PR RES .PR
mode .xint = int;
.xint sum sq:=0;
for i while
  sum sq≠70×70
do
  sum sq+:=i↑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. These contexts are:

N

a
m
e

Context location Coercions available in this context Coercion examples
Soft Meek Weak Firm Strong
S

t
r
o
n
g

Right hand side of:
  • Identity-declarations, as "~" in: <lang algol68>REAL x = ~</lang>
  • Initialisations, as "~" in: <lang algol68>REAL x := ~</lang>

Also:

  • Actual-parameters of calls, as "~" in:<lang algol68>PROC: sin(~)</lang>
  • Enclosed clauses of casts, as "~" in: <lang algol68>REAL(~)</lang>
  • Units of routine-texts
  • Statements yielding VOID
  • All parts (but one) of a balanced clause
  • One side of an identity relation, as "~" in: <lang algol68> ~ IS ~</lang>
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: <lang algol68>INT to LONG INT INT to REAL REAL to COMPL BITS to []BOOL BYTES to STRING</lang> A variable can also be coerced (rowed) to an array of length 1.

For example: <lang algol68>INT to [1]INT REAL to [1]REAL</lang> etc

F

i
r
m

  • Operands of formulas as "~" in:<lang algol68>OP: ~ * ~</lang>
  • Parameters of transput calls
Example:

<lang algol68>UNION(INT,REAL) var := 1</lang>

M

e
e
k

  • Trimscripts (yielding INT)
  • Enquiries: e.g. as "~" in the following

<lang algol68>IF ~ THEN ... FI</lang> and <lang algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</lang>

  • Primaries of calls (e.g. sin in sin(x))
Examples:

<lang algol68>REF REF BOOL to BOOL REF REF REF INT to INT</lang>

W

e
a
k

  • Primaries of slices, as in "~" in: <lang algol68>~[1:99]</lang>
  • Secondaries of selections, as "~" in: <lang algol68>value OF ~</lang>
Examples:

<lang 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</lang>

S

o
f
t

The LHS of assignments, as "~" in: <lang algol68>~ := ...</lang> Example:
  • deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang>

For more details about Primaries and Secondaries refer to Operator precedence.

Code Specimen

Subcategories

This category has the following 3 subcategories, out of 3 total.

Pages in category "ALGOL 68"

The following 200 pages are in this category, out of 1,015 total.

(previous page) (next page)

C

(previous page) (next page)