Tuesday, 2 May

Download Report

Transcript Tuesday, 2 May

Lecture 24:
CS655
Jeopardy
Who wants to be
a quintupledeca-billionaire?
CS655: Programming Languages
University of Virginia
Computer Science
David Evans
http://www.cs.virginia.edu/~evans
Menu





Course Summary
 Goals from Lecture 1
Musical Interlude: Geoff Stoker
Jeopardy
Remember to fill out official course evaluations
before Friday
Tomorrow, 3:30 – Chris Hawblitzel talk
 “Adding Operating System Structure to
Language-Based Protection”
 Student Roundtable at 5:00
27 July 2016
University of Virginia CS 655
2
Final
Everyone should have received email with
the final schedule
 Final pledge:
 After you take final, don’t help others
who have not taken it.
 Before you take final, don’t seek help
from others who have taken it.

27 July 2016
University of Virginia CS 655
3
Goal #1
When you need to invent a
language (and most of you
will at some point in your
career) you will design it, not
just make it up.
27 July 2016
University of Virginia CS 655
4
Goal #2
When you design your language,
you will have sufficient knowledge
of other languages not to repeat
their mistakes, and solid enough
theory background to describe your
language well.
27 July 2016
University of Virginia CS 655
5
Languages and Tools
Languages: FORTRAN, Algol60, BLISS,
C, Pascal, Algol68, CLU, Ada, C++, Java,
Eiffel, Sather, FP, FL, ML, Scheme, Linda,
JavaSpaces, AspectJ, PROLOG, GPL
 Formal tools: BNF, Operational Semantics,
Type Judgments, Axiomatic Semantics,
Lambda Calculus, Denotational Semantics

27 July 2016
University of Virginia CS 655
6
Goal #3
You will become better at
programming and building
systems. You will think more
clearly and maybe even write
better.
27 July 2016
University of Virginia CS 655
7
Goal #4
Some of you will do projects
that lead to conference papers
or thesis topics. All of you will
be able to understand nearly all
PLDI papers and many POPL
papers.
27 July 2016
University of Virginia CS 655
8
I think that it’s extraordinarily important that we in computer
science keep fun in computing. When it started out, it was an
awful lot of fun. Of course, the paying customer got shafted
every now and then, and after a while we began to take their
complaints seriously. We began to feel as if we really were
responsible for the successful, error-free perfect use of these
machines. I don't think we are. I think we're responsible for
stretching them, setting them off in new directions, and keeping
fun in the house. I hope the field of computer science never loses
its sense of fun. Above all, I hope we don't become missionaries.
Don't feel as if you're Bible salesmen. The world has too many
of those already. What you know about computing other people
will learn. Don't feel as if the key to successful computing is
only in your hands. What’s in your hands, I think and hope, is
intelligence: the ability to see the machine as more than when
you were first led up to it, that you can make it more.
Alan Perlis (quoted in Abelson & Sussman)
27 July 2016
University of Virginia CS 655
9
Musical Interlude
27 July 2016
University of Virginia CS 655
10
Jeopardy Rules




$1B, $2B, $4B – raise hand to answer, first team
spotted will be asked to answer, whoever is picked
must answer right away
 For questions with hints, no penalty for wrong
answer before hints revealed (but can’t answer
again);
 For other questions (or after hint revealed), lose
value for wrong answer.
All teams answer $10B questions, answer value at
discretion of staff
Projects category: group who did the project cannot
answer, until everyone else gives up
Team with the highest total, gets prizes (no cash prizes)
27 July 2016
University of Virginia CS 655
11
Jeopardy
Zero,
One,
Infinity
Call-byname, Callby-value
1
1
2
Type
Inference
Syntax and
Semantics
Exception
Handling
1
1
1
1
2
2
2
2
2
4
4
4
4
4
4
10
10
10
10
10
10
Projects
(All point values in Billions)
27 July 2016
University of Virginia CS 655
12
Zero, One, Infinity 1
How many reserved
words are there in
PL/I?
0
27 July 2016
Choices
23
57
University of Virginia CS 655
178
13
Zero, One, Infinity 1
How many reserved
words are there in
PL/I?
0
Choices
23
57
178
Return
27 July 2016
University of Virginia CS 655
14
Buffer
27 July 2016
University of Virginia CS 655
15
Zero, One, Infinity 2
Using the numeral system we
defined in class, what number does
(z.z (xy.y) (x.x)) represent?
0
27 July 2016
Choices
1
2
Not Number
University of Virginia CS 655
16
Zero, One, Infinity 2
Using the numeral system we
defined in class, what number does
(z.z (xy.y) (x.x)) represent?
0
Choices
1
2
Not Number
Return
27 July 2016
University of Virginia CS 655
17
Buffer
27 July 2016
University of Virginia CS 655
18
Zero, One, Infinity 4
What are: “strong”, “firm”,
“meek”, “weak”, and “soft”?
Context strengths inAnswer
Algol 68 (control which
coercions are allowed)
Return
27 July 2016
University of Virginia CS 655
19
Buffer
27 July 2016
University of Virginia CS 655
20
Zero, One, Infinity 10
A.
B.
C.
D.
E.
F.
G.
Put the following in order by number of pages,
from least to most:
Ada Military Standard [1980]
Revised Report on Algol60 [1963]
Beowulf [~750]
C++ Standard [1997]
Common LISP, The Language [1990]
FIFA Laws of the Game [1999]
US Tax Code [1999]
27 July 2016
University of Virginia CS 655
21
Zero, One, Infinity 10
Put the following in order by number of pages,
from least to most:
B. Algol60 Report (16)
F. FIFA Laws of the Game (29)
C. Beowulf (120)
A. Ada Military Standard [1980] (233)
D. C++ Standard (680)
E. Common LISP, The Language (1029)
G. US Tax Code (6000)
Return
27 July 2016
University of Virginia CS 655
22
Buffer
27 July 2016
University of Virginia CS 655
23
Call by Name, Call by Value 1
Which famous language
designer has said he can be
called by name or called by
value?
Niklaus Wirth – “Europeans
Answer call him by name,
but Americans call him by value.” (Nickel’s Worth)
Return
27 July 2016
University of Virginia CS 655
24
Buffer
27 July 2016
University of Virginia CS 655
25
Call by Name, Call by Value 2
Which language designers
received a National Medal of
Technology last year?
Picture
Return
27 July 2016
University of Virginia CS 655
26
Call by Name, Call by Value 2
Ken Thompson (left) and Dennis Ritchie
Answer
(for C and UNIX)
Return
27 July 2016
University of Virginia CS 655
27
Buffer
27 July 2016
University of Virginia CS 655
28
Call by Name, Call by Value 4
What does ECOOP
stand for?
European Conference for Object-Oriented
Programming Answer
Return
27 July 2016
University of Virginia CS 655
29
Buffer
27 July 2016
University of Virginia CS 655
30
Call by Name, Call by Value 10
Describe or make up a naming myth for each of
the following languages:
APL
BLISS
Forth
JOVIAL
Scheme
SNOBOL
(Note: an amusing creative answer is sometimes
better than a dull correct one!)
27 July 2016
University of Virginia CS 655
31
Call by Name, Call by Value 10
APL
“A Programming Language”
BLISS
Basic Language for Implementation of System
Software (or allegedly, “System Software
Implementation Language, Backwards”)
Forth
“Fourth” for fourth-generation language;
implemented on second-generation computer
with 5-letter limit.
27 July 2016
University of Virginia CS 655
32
Call by Name, Call by Value 10
JOVIAL
Jule’s Own Version of IAL
Scheme
Successor to “Planner” and “Conniver”,
originally “Schemer”, but limited to 6 letters.
SNOBOL
“StriNg Oriented symBOlic Language”
Return
27 July 2016
University of Virginia CS 655
33
Buffer
27 July 2016
University of Virginia CS 655
34
Type Reconstruction 1
What type does Hindley-Milner type
reconstruction produce for:
 g.  f.  x. g (f x)
g:    f:   
x: 
Term: (  ) Answer
((  )  (  ))
Return
27 July 2016
University of Virginia CS 655
35
Buffer
27 July 2016
University of Virginia CS 655
36
Type Reconstruction 2
Which of the following type declarations
were valid in Algol 60?
A.
integer i
AllAnswer
except
B.
Boolean b
char.
C.
char c
D.
array a
E.
real array a[if i<0 then 2 else -2:30]
Return
27 July 2016
University of Virginia CS 655
37
Buffer
27 July 2016
University of Virginia CS 655
38
Type Reconstruction 4
 A.
 B.
 C.
 D.
 E.
X F.
Which of the following were
women?
First programmer
Creator of first compiler
Author of first major study of
programming languages
Originator of most widely-used
language of 60s, 70s and 80s
Designer of first language to
support data abstraction
Leader of Ada project
Names
Ada Lovelace
Admiral Hopper
Jean Sammet
(COBOL) Admiral
G. Murray Hopper
Prof. Liskov
Jean Ichbiah
Answer
27 July 2016
University of Virginia CS 655
Return
39
Buffer
27 July 2016
University of Virginia CS 655
40
Type Reconstruction 10
What type does ML infer for sort as define
below?
fun split [] = ([], [])
| split [h] = ([h], [])
| split (x::y::t) = let val (s1, s2) = split t
in (x::s1, y::s2) end
fun merge ([], x) = x: int list // Explicit declarations mean x must
| merge (x, []) = x: int list // have type int list.
| merge (h1::t1, h2::t2) =
if h1 <int h2 then h1::merge (t1, h2::t2)
else h2::merge (h1::t1, t2);
fun sort [] = []
| sort x = let val (p, q) = split x
in merge (sort p, sort q) end;
27 July 2016
University of Virginia CS 655
41
Type Reconstruction 10
sort has type: ‘a list  int list
There is a “bug” in sort, it can’t sort a single
element:
sort [x] = merge (sort [x], sort [])
= merge (merge (sort[x], sort []), [])
= ...
Hence, type unifier never has to unify ‘a list and
int list!
See http://www.plover.com/~mjd/perl/yak/typing/typing.html
27 July 2016
University of Virginia CS 655
42
Buffer
27 July 2016
University of Virginia CS 655
43
Syntax and Semantics 1
Using standard axiomatic semantics for
an Algol-like language, what is the
weakest pre-condition P such that:
P
{ if (y > 3) x := 5; else x := x + 1; }
x = 12  y = 2
Answer
false
27 July 2016
University of Virginia CS 655
Return
44
Buffer
27 July 2016
University of Virginia CS 655
45
Syntax and Semantics 2
What Invariant can be used to prove:
sum = 0  n = x.length  i = 0
{ while (i < n)
sum := sum + x[i]; i := i + 1;
end }
Inv
=
n
=
x.length
Answer
x.length -1
 sum =  x[j]
sum =  x[i]
i=0
27 July 2016
j=0, i -1
University of Virginia CS 655
Return
46
Buffer
27 July 2016
University of Virginia CS 655
47
Syntax and Semantics 4
DAILY
DOUBLE
Topic: Denotational Semantics
27 July 2016
University of Virginia CS 655
48
Syntax and Semantics 4
What would be unusual about our language
if its statement semantics was described by
the denotational semantics rules:
L : StatementList  (  )
L [[]] = { (, ) |  }
L [[Statement ; StatementList ]] =
S [[Statement]]  L [[StatementList]]
Answer
27 July 2016
University of Virginia CS 655
49
Syntax and Semantics 4
L [[Statement ; StatementList ]] =
S [[Statement]]  L [[StatementList]]
The statements are modifying the state in
reverse order!
b := a; a := a + 1;
S [[b := a]] (S [[a := a + 1]]  )
Return
27 July 2016
University of Virginia CS 655
50
Buffer
27 July 2016
University of Virginia CS 655
51
Syntax and Semantics 10
Use a standard operational semantics to describe
the Linda primitives:
 out (t) – add tuple t to tuple space
 take (s)  t – returns and removes tuple t
matching template s
You may assume a procedure
match_and_bind (: store, s: template, t: tuple)
that returns true if tuple t matches template s, and
adds appropriated bindings to ; otherwise, it
returns false and does nothing.
Return
27 July 2016
University of Virginia CS 655
52
Buffer
27 July 2016
University of Virginia CS 655
53
Exception Handling 1
What is the difference between
exception propagation semantics in
CLU and Java? Explain the
advantages/disadvantages of each
approach.
Answer
27 July 2016
University of Virginia CS 655
54
Exception Handling 1
In CLU, an exception that is not
handled by the calling context, is
propagated up the call chain as an
“unhandled exception”. In Java, the
programmer must provide handlers for
all exceptions except
RunTimeExceptions.
Return
27 July 2016
University of Virginia CS 655
55
Buffer
27 July 2016
University of Virginia CS 655
56
Exception Handling 2
What must be true about a
language for the typing rule shown
below to be sound?
T1  T2
array[T1]  array [T2]
Array assignment, parameter passing and result
passing must beAnswer
by value (copy, not sharing).
27 July 2016
University of Virginia CS 655
Return
57
Buffer
27 July 2016
University of Virginia CS 655
58
Exception Handling 4
The decrease in the net worth of the secondary
co-author of the first BASIC interpreter for the
Altair in the past month is closest to the annual
GDP of which country?
$1.2B
A.
Andorra
$33B
B.
Bulgaria
Values
C.
Egypt
Answer
$188B
D.
Ireland
$67B
E.
Mexico
$815B
27 July 2016
University of Virginia CS 655
59
Buffer
27 July 2016
University of Virginia CS 655
60
Exception Handling 10
1.
2.
3.
4.
5.
For each system, identify the language in
which it was programmed:
AWACS (air defense)
Multics
Unix
WorldWideWeb (first Web server &
browser)
X-Windows
27 July 2016
University of Virginia CS 655
61
Exception Handling 10
1.
2.
3.
4.
5.
For each system, identify the language in
which it was programmed:
AWACS (air defense) – JOVIAL
Multics – PL/I
Unix – C
WorldWideWeb (first Web server &
browser) – Objective C
X-Windows – CLU (now C)
Return
27 July 2016
University of Virginia CS 655
62
Buffer
27 July 2016
University of Virginia CS 655
63
Projects 1
In the Tabasco environment-updating rule for if,
what does  mean?
A {S1} A1
A {S2} A2
---------------------------------------- [if-else]
A{ if exp1: S1 else: S2} A1 A2
Answer
(A1A2) |- var: secure
iff
Return
A1|-var: secure and A2|-var: secure
27 July 2016
University of Virginia CS 655
64
Buffer
27 July 2016
University of Virginia CS 655
65
Projects 2
Why is ParTy better than
Pizza?
Faster execution because run-time
type checks areAnswer
not needed.
27 July 2016
University of Virginia CS 655
Return
66
Buffer
27 July 2016
University of Virginia CS 655
67
Projects 4
What is the difference between
“consistent pass-by-value” and
“inconsistent pass-by-value”?
27 July 2016
University of Virginia CS 655
68
Projects 10
Give an elevator speech for the next
group’s project:
1. Exception Mechanisms
2. Static Detection of Buffer Overflow
3. ParTy
4. Tabasco
5. JIST
6. Pass-by-Value Services in Object
Component Software
27 July 2016
University of Virginia CS 655
69
Buffer
27 July 2016
University of Virginia CS 655
70
Final Jeopardy:
Abstraction Functions and
Rep Invariants
27 July 2016
University of Virginia CS 655
71
Final Jeopardy
Stroustrup’s “What is Object-Oriented
Programming” paper used the following example:
class vector {
int *v; int sz;
vector::vector (int s) { // Creates a new vector of size s.
if (s < 0) error (“Size must be non-negative.”);
sz = s; v = new int[s];
}
int vector::operator[] (int i) {
if (0 < i || sz <= i) error (“Bad selector!”);
return v[i];
}
}
What is an abstraction function and rep invariant
for vector?
27 July 2016
University of Virginia CS 655
72
Buffer
27 July 2016
University of Virginia CS 655
73