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.

  1. Answer the following questions concerning programming languages:
    1. 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.
    2. 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)
    

  2. 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)
    
    1. What does this program print, when Scala uses static scoping? Explain how you get the result.
    2. What would it print if the language used dynamic scoping? Explain how you get the result.
                                                                                             (10 points)
    

  3. Answer the following questions concerning programming languages:
    1. Describe four common parameter-passing modes. Give enlightening program examples and explain them thoroughly.
    2. What is a higher-order function (also known as a functional form)? Give enlightening program examples and explain them thoroughly.
                                                                                             (10 points)
    

  4. 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)