Back
ExamFull examExam paper only

19 09 13

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages 2013.09.19 Notes • Total available time: 1h 30’. • You may use any written material you need. • You cannot use computers or phones during the exam. 1 Scheme (9 points) Define an object, using the “closures as objects” technique seen in class,

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 2013.09.19 Notes • Total available time: 1h 30’. • You may use any written material you need. • You cannot use computers or phones during the exam. 1 Scheme (9 points) Define an object, using the “closures as objects” technique seen in class,

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 2013.09.19 Notes • Total available time: 1h 30’. • You may use any written material you need. • You cannot use computers or phones during the exam. 1 Scheme (9 points) Define an object, using the “closures as objects” technique seen in class, that works as a simple immutable container of integer numbers. It must offer two methods: member?, that checks if a number is contained in the object; and subsetsum, that checks if a given number is the sum of elements contained in the object (at most each element must be taken once). For instance, if you define(define ob (make-object ’(3 2 7))) , then (ob ’member? 9) is false, while (ob ’subsetsum 9) is true. Hint: you can call this procedure in your code: (define (subsets e) (let loop ((l e) (out ’(()))) (if (null? l) out (loop (cdr l) (append out (map (lambda (x) (cons (car l) x)) out)))))) 2 Haskell (11 points) Define the function infixes, which takes a list g as input and returns the list of all infixes (i.e. non-empty contiguous sublists) of g. For instance, infixes "ciao" is the list ["o","ao","iao","ciao","a","ia","cia","i","ci","c"] (remember that a string is a list of characters in Haskell). 3 Prolog (11 points) Consider binary trees represented as a hierarchic lists, where each node is a list [node, subtree1, subtree2]. Leaves are just symbols. In the colored subtree problem, we take as input a tree, and put into each internal node a number representing the number of different leaves present in its subtrees. E.g. given this tree: [R,[X,yellow,brown],[Y,blue,yellow]] the solution is: R = 3, X = Y = 2. Define the col_tree predicate, that solves the colored subtree problem. Hint: the predicate union(X,Y,Z) holds if the list Z is the union of X and Y, seen as sets. 1 Solutions Scheme (define…

Preview

First page of the document.

First page: 19 09 13