Helsingin yliopisto
/
Tietojenkäsittelytieteen laitos
/
Ohjelmointikielten periaatteet
/
Copyright © 2009 Arto Wikla.
Ohjelmointikielten periaatteet, koe 27.4.2009/AW
Kirjoita jokaisen vastauspaperisi alkuun kurssin nimi ja kokeen
päivämäärä sekä nimesi, opiskelijanumerosi ja allekirjoituksesi.
Vaikka kysymykset ovat harjoitustehtävien tapaan englanniksi,
vastata saa suomeksi, ruotsiksi tai englanniksi. Vastauksissa saa
vapaasti yhdistelläkin näitä kieliä, kunhan pitää huolen siitä, että
vastaus on mahdollista ymmärtää.
Principles of Programming Languages:
Write the name of the course, the date of the exam, your name, student
number and signature on each paper.
-
Answer the following questions concerning programming languages:
- Explain the distinctions (if any)
between the lifetime, the visibility, and
the scope of a name-to-object binding?
Give enlightening program examples and explain them thoroughly.
- Explain the difference between static and dynamic
scope.
Why does the use of dynamic scoping imply the need for run-time type
checking?
Give enlightening program examples and explain them thoroughly.
(10 points)
- Consider the following Scala program:
var x = 31 // global variables
var y = 91
def add {x = x + y}
def second(P: => Unit) {var x = 47; P}
def first {var y = 71; second(add)}
// Main:
first
println(x)
- What does this program print, when Scala uses static scoping?
Explain how you get the result.
- What would it print if the language used dynamic scoping?
Explain how you get the result.
(10 points)
- Answer the following questions concerning programming languages:
- Describe four common parameter-passing modes.
Give enlightening program examples and explain them thoroughly.
-
What is a higher-order function (also known as a functional
form)?
Give enlightening program examples and explain them thoroughly.
(10 points)
- Explain the terms trait and mix-in in Scala language.
Give enlightening program examples and explain them thoroughly.
What are the differences between traits
and multiple inheritance? What are the differences between
traits and Java-style interfaces?
(10 points)