← Indietro
EsameEsame completoTesto d’esame

24 09 12 1

Esame completo di Principles of Programming Languages per il corso di Computer Engineering presso Politecnico di Milano. Materiale proveniente dall’archivio storico Studwiz e classificato per la consultazione online.

Principles of Programming LanguagesEsame completo

Informazioni sul documento

Cosa trovi in questo materiale

Esame completo di Principles of Programming Languages per il corso di Computer Engineering presso Politecnico di Milano. Materiale proveniente dall’archivio storico Studwiz e classificato per la consultazione online.

Qualità dell’importazione: il testo è stato estratto direttamente dal documento originale.

Contenuti estratti dal documento

Passaggi rappresentativi riconosciuti nelle diverse parti del materiale. Il testo completo resta presente nella pagina per la ricerca, mentre l’anteprima compatta rende più semplice la lettura.

Pagina 1

Principles of Programming Languages 2012.09.24 Notes • Total available time: 2h 30’. • You may use any written material you need. • You cannot use computers, phones or laptops during the exam 1 Haskell (10 points) 1. Please define a procedure getCSV that is used, in the Monad IO, to get a field in a Comma Separated Values textfile (assume as separators both the , and ; characters). 2. Define the unless procedure in the IO Monad. It takes two arguments, a condition c and a body b, and repeats b unless c becomes true (in a sense, it is a “dual” of while). 3. Alfio is experimenting with Haskell, and wants to define a very simple object-oriented-like system, where an object is just a container of a datum, and a list of “methods”, i.e. functions having signature a→ a→ a, where a is the type of the datum. This is an example object defined by Alfio: myob = Obj (5, [("add", \self -> \x -> self+x), ("sqr", \self -> \x -> self*self)]) -- x is ignored Please, help Alfio to define both the needed datatype, and the call function for invoking methods. E.g. call myob "add" -2 should return 3. 2 Prolog (8 points) 1. Please, define a Prolog procedure to obtain from a list the last but one element. If the number of elements in the list is less than 2, it should fail. 2. Define a nested version of the previous procedure: when the last but one element of the list is another list, this new procedure should look to the last but one element, until it finds an atomic value. E.g. ?- nestedlastb1([1,2,[3,3,[5,2,2],6],4],X). X = 2. 1 3 Scheme (7 points) Scheme does not natively support matrices: there are just vectors. Of course, we can define a matrix as a vector of vectors, each having the same size. 1. Please define make-matrix, with three parameters: r, c, and f ill. This procedure returns a matrix having…

Anteprima

Prima pagina del documento.

Prima pagina: 24 09 12 1