38
David Evans http://www.cs.virginia.edu/ ~evans CS655: Programming Languages University of Virginia Computer Science Lecture 12: All About Algol Algol60 was appreciated, almost immediately, as a rounded work of art. ... While Algol60 was no intellectual revolution, it was to become a universal tool with which to view, study and proffer solutions to almost every kind of problem in computation. Rarely has a construction so useful and elegant emerged as the output of a committee of 13 meeting for about 10 days. Alan Perlis, 1978

David Evans cs.virginia/~evans

  • Upload
    tave

  • View
    39

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture 12: All About Algol. - PowerPoint PPT Presentation

Citation preview

Page 1: David Evans cs.virginia/~evans

David Evanshttp://www.cs.virginia.edu/~evans

CS655: Programming LanguagesUniversity of VirginiaComputer Science

Lecture 12: All About Algol

Algol60 was appreciated, almost immediately, as a rounded work of art. ... While Algol60 was no intellectual revolution, it was to become a universal tool with which to view, study

and proffer solutions to almost every kind of problem in computation. Rarely has a construction so useful and

elegant emerged as the output of a committee of 13 meeting for about 10 days.

Alan Perlis, 1978

Page 2: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 2

Menu• PS2, PS3• Algol Background• Evolution of Algol Procedures• Ambiguities in Algol60 [Knuth]• Algol 68

Page 3: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 3

PS2 Comments• Everyone got the quantum scheme

interpreter to mostly work – good job!

• No one wrote one elegantly or concisely enough to get 10/10, or to be worth handing out as solutions (although some came close).

• No one used deeplistmerge in their solution!

Page 4: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 4

PS2 Comments

• This isn’t a software engineering course, if it were I would be appalled at the test cases everyone used!

• Test cases should always cover:– Error cases (observe failures)– Boundary cases (empty quists, singletons,

etc.)

Page 5: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 5

PS3: Out Today

• Pick an interesting target– Don’t pick C++ unless you have something

creative to say (way too easy)– Best paper will convince me about a

language I like (C, CLU, FL, Scheme)

• Write well– Make a web page for a humanities grad

student

Page 6: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 6

Communications of the ACMJanuary 1963 January 2001 Advantage

CoverBlack, white and blue glimpse of Algol 60 Report

Glossy frightening colorful cartoon about e-Democracy

Page 7: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 7

Communications of the ACMJanuary 1963 January 2001 Advantage

CoverBlack, white and blue glimpse of Algol 60 Report

Glossy frightening colorful cartoon about e-Democracy

1963

Page 8: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 8

Communications of the ACMJanuary 1963 January 2001 Advantage

CoverBlack, white and blue glimpse of Algol 60 Report

Glossy frightening colorful cartoon about e-Democracy

1963

Code Excerpts 19 1 (pseudocode) 1963

Proofs 3 None 1963Algorithms 10 None 1963Letters from US Presidents

Page 9: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 9

Communications of the ACMJanuary 1963 January 2001 Advantage

Cover Black, white and blue glimpse of Algol 60 Report

Glossy colorful cartoon about e-Democracy

1963

Code Excerpts 19 1 (pseudocode) 1963Proofs 3 None 1963Algorithms 10 None 1963Letters from US Presidents

1 (Kennedy, p. 45) 0 1963

Page 10: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 10

Communications of the ACMJanuary 1963 January 2001 Advantage

Advertisements Mostly sexist ads for programmers, starting salaries $18,000; some adds for languages: “Big computer Fortran for desk-size computer users. Compiles 125 statements per minute!...start as low as $1500/month.”

46 pages of ads for overpayed, cushy academic positions, glossy full-color ads for conferences (CHI, user experience, performance evaluation and telecommunication, etc.), books

2001

Web Version None Yes (if you pay ACM) 2001Best-Selling Music

Beatles, “Please Please Me”

Beatles, 1 Tie

Page 11: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 11

Before Algol

• Ad hoc syntax descriptions, didn’t pay much attention

• Operational language descriptions

• Machine/compiler specific

Page 12: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 12

IBM 704 Fortran manual, 1956

Page 13: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 13

Some Fortran Code

• LoopsDO 10 I=1.10

Assigns 1.10 to the variable DO10I

DO 10 I=1,10

Loops for I = 1 to 10

(Often blamed for loss of Mariner-I, but probably not true.)

Page 14: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 14

Procedures in Fortran

• Original “Programmer’s Reference Manual” [1956] – no way to define a function; could call pre-defined functions

• Revised in 1957:– Define a function on a single line, with arguments

• Call-by-reference:SUBROUTINE INCR(I) I = I + 1 RETURN END

CALL INCR (2)N = 2 + 2

Page 15: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 15

Algol Background• 1955: GAMM (European association of

applied mathematics and mechanics) sets up committee to study development of a universal machine-independent programming language

• May 1957: ACM forms committee to study universal programming language

• October 4, 1957:

Page 16: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 16

1958• Oct 1957: agree to joint effort• 1958: Preliminary Report – International

Algebraic Language. Objectives:– As close as possible to standard mathematical

notation, readable with little further explanation– Useable for describing computing processes in

publications– Mechanically translatable into machine programs

Page 17: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 17

Algol 58Function Procedure

Body Expression Compound Statement

Parameters Call-by-value Call-by-name

Identifiers Non-parameters are global

Only use parameters

Syntactic Use Only as an expression operand

Statement or expression operand

Page 18: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 18

Zürich Report (1959)

• Removed distinction between functions and procedures: allow procedures to return a value, blocks

• Separate input and output parameter listsprocedure F (Pi0, Pi1, ...) =: (Pp0, Pp1, ...)

• Can list parameter as both input and output• Procedure call by text replacement, replace

return to go to to statement after procedure• Didn’t support recursion (proprosal to add

recursive delimiter rejected)

Page 19: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 19

Algol 60 Committee• Committee consisting of 7 Europeans and 6

Americans (William Turanski died)– Europeans wanted a language to use– Americans using Fortran, other languages, etc.

“It is probably true to say that the collective knowledge of the total group of participants in the development of Algol 60 included all there was to be known about programming languages at the time.” [Naur 78]

John Backus (Fortran), Alan Perlis (first Turing award), Peter Naur (ACM President), John McCarthy (LISP)

Page 20: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 20

Three Languages• Reference Language

– For use by committee, described in report and used in official Algol publications

• Publication Language– Variations on reference language for

publication, close correspondence to reference language

• Hardware Representations– Condensed languages for machine input

Page 21: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 21

Why three languages?“After two days of probing attitudes and suggestions, the meeting came to a complete deadlock with one European member pounding on the table and declaring: “No! I will never use a period for a decimal point”. Naturally the Americans considered the use of comma as decimal point to be beneath ridicule. That evening Wegstein visited the opposing camps and proposed defining the three levels of language.”

Alan Perlis, The American Side of the Development of Algol, ACM SIGPLAN Noticies, August 1978.

Page 22: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 22

Algol60 Procedures• Call-by-value or call-by-name determined by

specifications – Removed need for distinction between input and

output parameters

• Defined by text replacement:– Value: additional block, local variables assigned to

parameter– Name: replace throughout body enclosed parameter

in parentheses “whenever syntactically possible”

• Modified body inserted in place of call

Page 23: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 23

Jensen’s Devicereal procedure InnerProduct (z, y,n, j);

value n; integer n;begin

real a; a := 0;for j = 1 step 1 until n do a := a + z * y;InnerProduct := a

endSample calls:

InnerProduct (A[i], B[i], 10, i)InnerProduct (M1[i,i], M2[k,i], 10, i)

Page 24: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 24

Call: InnerProduct (A[i], B[i], 10, i)begin

real a; a := 0;for i = 1 step 1 until 10 do a := a + A[i] * B[i];InnerProduct := a

end

Call: InnerProduct (M1[i,i], M2[k,i], 10, i)begin

real a; a := 0;for i = 1 step 1 until 10 do a := a + M1[i,i] * M2[k, i];IP := a

end

Page 25: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 25

Ambiguity 1: Side Effects

• If side effects are permitted, order of evaluation matters!

begin integer a;

integer procedure double(n)

value n; integer n; double := n := n * 2;

a := 2; outint (a * double(a) * double(a));

end.

• Question: Have modern languages resolved this?

Page 26: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 26

Ambiguity 3: For Loops• Overly general and complicated

– What were they (over) reacting to?

• Semantics defined by formal translation (but they probably didn’t really mean it)for V := A step B until C do S

V := A; L1: if (V – C) * sign(B) > 0 then go to done;

S;V := V + B;go to L1;

Page 27: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 27

Ambiguity 4: Specifications

• 5.4.5: “Specifications (type declarations) of formal parameters called by value must be supplied and specifications of formal parameters called by name may be omitted.” (I don’t understand Knuth’s confusion.)

• What are the advantages and disadvantages of not specifying call-by-name parameters?

Page 28: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 28

Ambiguity 8: Numeric Labels<label> ::= <identifier> | <unsigned integer>

begin

integer val;

val := 7

go to val;

7: val := 8; go to val; comment yikes!

val: …

end

Page 29: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 29

Correction 1: if/else definition

“The construction

else <unconditional statement>

is equivalent to

else if true then <unconditional statement>”(4.5.3.2)

LISP (before Algol 60):(cond (p1 e1) (p2 e2) ... (pn en))

Go from left to right, first pi that is true, value is ei;If no pi is true, value of expression is undefined

Page 30: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 30

Influence of AlgolFORTRAN

Algol60

Simula67

CLUPascalC

1954

1960

1970

1980

CPL

BCPL

Algol68 C

omm

ittee

Algol68

Classes

PL/I

Modula-2

Oberon

Smalltalk

Algol-W

C++ Modula-3

2000Java

Page 31: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 31

Algol 68 Committee• Unruly, political, infighting, unresolved conflicts• 1965 Meeting: two proposals

– Wirth and Hoare: extend Algol 60 with records– van Wijngaarden: design new language, minimal

concepts combined in orthogonal way, describe using W-grammar, incomplete and incomprehensible

• Kept postponing meetings because drafts weren’t ready

• Accepted report (18 of 28 original members)• First implementation: 1970• Revised Report: 1975 (first readable

presentation)

Page 32: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 32

Othogonality in Design

m

n

Co

mb

inat

ion

Tec

hn

iqu

es

Building Blocks

m*n things

Some of those m*n things will be hardto understand or implement, so you endup with either exceptions or complexity.

Page 33: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 33

Orthogonality in Algol68

• Referencesref x was a type, so ref ref x was a type.refs for parameters, so refs for local varaibles.

• Proceduresprocs for parameters, so proc variables, parameters,

results and in-line constructors

• Compare to Pascal: “References are dangerous and complicated, so only allow them where they are absolutely necessary.”– Functions can only return simple types, passed

procedures cannot have ref parameters, etc.

Page 34: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 34

W-Grammars

• Invented by Van Wijngaarden• Can describe any computable language!

(Contrast BNF: only context-free languages)

Simplified example:reference to MODE assignation :: reference to MODE destination, :=,

MODE source.MODE :: real ; integral ; reference to MODE; …

Page 35: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 35

Minority Report

• Signed by Edsger Dijkstra, C. A. R. Hoare and 5 others

• Some complaints about complexity of language (reference concept taken too far)

• Many complaints about description of language (complexity of W-Grammars)

• Controversy over publication (suppressed by IFIP)

• Copy on your manifest

Page 36: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 36

Doomed to Failure

Algol 6869 Published first report75 Published revised report

“one of the most unreadable documents which has ever been printed”

76 “Algol 68 with Fewer Tears”77 Tanenbaum’s Tutorial

(See Knuth’s quote on Manifest.)

Page 37: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 37

What things in Java did not come directly from Algol 60?

• Garbage collection (Lisp [1959])

• Exceptions (CLU [1977] had better)

• User-defined types, structs (Algol 68 had these “better” than Java)

• Data abstraction (confused in Pascal, better in CLU)

• Objects, Dynamic Dispatch (Simula [1967])

• Concurrency (Algol 68 had better (?))

Page 38: David Evans cs.virginia/~evans

27 Feb 2001 University of Virginia CS 655 38

Charge

• Lots of reading to do...– Problem Set 3– Read Gifford’s notes on Operational

Semantics– Read about Algol68 if you have time

• Pick your target and content for PS3 carefully...