Back
ExamFull examExam paper only

10 02 16 1

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages 2016.02.10 Notes • NAME: __________________________________ • Did you present a small project? YES / NO • Total available time: 2h. • Y ou may use any written material you need. • Y ou cannot use computers or phones during the exam.

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 2016.02.10 Notes • NAME: __________________________________ • Did you present a small project? YES / NO • Total available time: 2h. • Y ou may use any written material you need. • Y ou cannot use computers or phones during the exam.

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 2016.02.10 Notes • NAME: __________________________________ • Did you present a small project? YES / NO • Total available time: 2h. • Y ou may use any written material you need. • Y ou cannot use computers or phones during the exam. Introduction Figure 1: Simply-linked circular list (Clist) A simply-linked circular list (called Clist from now on) is a list in which the last node points to the first node (see figure). It is sometimes useful to have a sentinel last node, i.e. a node that does not contain data. The sentinel is used e.g. to check if we have traversed the whole list. An empty list contains only the sentinel node, that points to itself. 1 Scheme 1.1 Data structure definition and constructors (7 points) Define a data structure for Clists (hint: use struct), together with a constructor for an empty Clist, and a variant of the cons operation for Clists, which adds a new element as the head of the previous Clist. 1.2 Map (4 points) Define cmap, a map operation for Clists. 1 2 Haskell 2.1 Type definition and Eq (5 points) Define a data structure for Clists with a data declaration. Make Clist an instance of Eq – beware: equality test must always terminate. 2.2 Conversions from/to ordinary lists (6 points) Define two functions list2clist and clist2list, that are used to convert an ordinary list to a Clist, and vice versa. Write their types. 2.3 Map (6 points) Define cmap, a map operation for Clists. Write its type. 3 Prolog (5 points) Define a predicate with one argument to check if a given string is a palindrome. E.g. palindrome("sator arepo tenet opera rotas") should return true. 2 Solutions Scheme (struct cnode (value next) #:mutable) (define *end* ’---end---) (define (cend) ; builds a sentinel node (let ((node (cnode *end* #f)))…

Preview

First page of the document.

First page: 10 02 16 1