Back
ExamFull examExam paper only

06 07 12

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages, 2012.07.06 Notes: - Total available time: 2h - You may use any written material you need - You cannot use computers, phones or laptops during the exam Exercise 1 a) Define an iterator for lists in Scheme, such that calling it returns an

Principles of Programming LanguagesFull exam

Document information

What's included in this study material

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages, 2012.07.06 Notes: - Total available time: 2h - You may use any written material you need - You cannot use computers, phones or laptops during the exam Exercise 1 a) Define an iterator for lists in Scheme, such that calling it returns an

Import quality: text was extracted directly from the original document.

Extracted content from the document

Representative passages recognised in different parts of the material. The full extracted text remains available to search, while this compact preview makes the page easier to read.

Page 1

Principles of Programming Languages, 2012.07.06 Notes: - Total available time: 2h - You may use any written material you need - You cannot use computers, phones or laptops during the exam Exercise 1 a) Define an iterator for lists in Scheme, such that calling it returns an element. When there are no more elements, it returns symbol <<end>>. E.g. (define il (make-iter '(1 2))) (il) returns 1 (il) returns 2 (il) returns <<end>> b) Define an analogous iterator for vectors. c) Define a new construct "for/in" which iterates on lists or vectors. E.g. (for x in '(1 2 3) (display x)) shows 123 (for x in '#(c a s a) (display x)(display ".")) shows c.a.s.a. Exercise 2 Consider the operation revmap which reverses a list and then performs a map: i.e. revmap (*2) [1,2,3] is [6,4,1] a) Define a Prolog implementation of revmap traversing the list only once. (HINT: use as many parameters as needed) b) Define a pure and strict Haskell implementation of revmap, possibly with linear time complexity (assuming that the mapped function has constant time complexity) and traversing the list only once. Exercise 3 You are currently working on the Padi project, a graphical interface for entry-level users. The performance team has observed several major slowdowns in some applications using Padi. It seems that the problem is due to some memory leaks related to the usage of classes ScrollBar and TextPane. In order to identify the problem, it is needed to track memory allocation and de- allocation of instances of those classes. You have to modify the C++ sources of Padi in order to: • every time an instance of ScrollBar or TextPane is allocated on the heap, the address and the size of the allocate block is be printed on standard error • every time a memory block holding an instance of ScrollBar or…

Preview

First page of the document.

First page: 06 07 12