Lecture 12: All About Algol

advertisement
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
CS655: Programming Languages
David Evans
University of Virginia
http://www.cs.virginia.edu/~evans
Computer Science
Menu
•
•
•
•
•
PS2, PS3
Algol Background
Evolution of Algol Procedures
Ambiguities in Algol60 [Knuth]
Algol 68
27 Feb 2001
University of Virginia CS 655
2
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!
27 Feb 2001
University of Virginia CS 655
3
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.)
27 Feb 2001
University of Virginia CS 655
4
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
27 Feb 2001
University of Virginia CS 655
5
Communications of the ACM
January 1963
Cover
27 Feb 2001
January 2001
Advantage
Black, white and
Glossy frightening
blue glimpse of Algol colorful cartoon
60 Report
about e-Democracy
University of Virginia CS 655
6
Communications of the ACM
January 1963
Cover
27 Feb 2001
January 2001
Black, white and
Glossy frightening
blue glimpse of Algol colorful cartoon
60 Report
about e-Democracy
University of Virginia CS 655
Advantage
1963
7
Communications of the ACM
January 1963
Cover
January 2001
Black, white and
Glossy frightening
blue glimpse of Algol colorful cartoon
60 Report
about e-Democracy
Advantage
1963
Code Excerpts
19
1 (pseudocode)
1963
Proofs
3
None
Algorithms
10
None
1963
1963
Letters from US
Presidents
27 Feb 2001
University of Virginia CS 655
8
Communications of the ACM
January 1963
Cover
Code Excerpts
Proofs
Algorithms
Letters from US
Presidents
27 Feb 2001
January 2001
Black, white and
Glossy colorful
blue glimpse of Algol cartoon about e60 Report
Democracy
19
1 (pseudocode)
3
None
10
None
1 (Kennedy, p. 45)
0
University of Virginia CS 655
Advantage
1963
1963
1963
1963
1963
9
Communications of the ACM
Advertisements
Web Version
Best-Selling
Music
27 Feb 2001
January 1963
January 2001
Advantage
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
None
Yes (if you pay ACM)
2001
Tie
Beatles, “Please
Please Me”
Beatles, 1
University of Virginia CS 655
10
Before Algol
• Ad hoc syntax descriptions, didn’t pay
much attention
• Operational language descriptions
• Machine/compiler specific
27 Feb 2001
University of Virginia CS 655
11
IBM 704
Fortran
manual, 1956
27 Feb 2001
University of Virginia CS 655
12
Some Fortran Code
• Loops
DO 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.)
27 Feb 2001
University of Virginia CS 655
13
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
27 Feb 2001
University of Virginia CS 655
14
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:
27 Feb 2001
University of Virginia CS 655
15
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
27 Feb 2001
University of Virginia CS 655
16
Algol 58
Function
Procedure
Body
Expression
Parameters
Call-by-value
Compound
Statement
Call-by-name
Identifiers
Non-parameters
are global
Only as an
expression
operand
Only use
parameters
Statement or
expression
operand
Syntactic Use
27 Feb 2001
University of Virginia CS 655
17
Zürich Report (1959)
• Removed distinction between functions and
procedures: allow procedures to return a
value, blocks
• Separate input and output parameter lists
procedure 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)
27 Feb 2001
University of Virginia CS 655
18
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)
27 Feb 2001
University of Virginia CS 655
19
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
27 Feb 2001
University of Virginia CS 655
20
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.
27 Feb 2001
University of Virginia CS 655
21
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
27 Feb 2001
University of Virginia CS 655
22
Jensen’s Device
real 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
end
Sample calls:
InnerProduct (A[i], B[i], 10, i)
InnerProduct (M1[i,i], M2[k,i], 10, i)
27 Feb 2001
University of Virginia CS 655
23
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
27 Feb 2001
University of Virginia CS 655
24
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?
27 Feb 2001
University of Virginia CS 655
25
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;
27 Feb 2001
University of Virginia CS 655
26
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-byname parameters?
27 Feb 2001
University of Virginia CS 655
27
Ambiguity 8: Numeric Labels
<label> ::= <identifier> | <unsigned integer>
begin
7:
val:
end
27 Feb 2001
integer val;
val := 7
go to val;
val := 8; go to val; comment yikes!
…
University of Virginia CS 655
28
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
27 Feb 2001
University of Virginia CS 655
29
Influence of Algol
FORTRAN
1954
1960
Algol60
Classes
CPL
BCPL
C
Simula67
PL/I
Algol-W
Algol68
Pascal CLU Smalltalk
1970
Modula-2
C++
Oberon
Modula-3
Java
27 Feb 2001
1980
2000
University of Virginia CS 655
30
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)
27 Feb 2001
University of Virginia CS 655
31
Combination Techniques
Othogonality in Design
n
27 Feb 2001
m*n things
m
Building Blocks
Some of those m*n things will be hard
to understand or implement, so you end
up with either exceptions or complexity.
University of Virginia CS 655
32
Orthogonality in Algol68
• References
ref x was a type, so ref ref x was a type.
refs for parameters, so refs for local varaibles.
• Procedures
procs 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.
27 Feb 2001
University of Virginia CS 655
33
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;
…
27 Feb 2001
University of Virginia CS 655
34
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
27 Feb 2001
University of Virginia CS 655
35
Doomed to Failure
Algol 68
69 Published first report
75 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.)
27 Feb 2001
University of Virginia CS 655
36
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 (?))
27 Feb 2001
University of Virginia CS 655
37
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...
27 Feb 2001
University of Virginia CS 655
38
Download