← Indietro
EsameEsame completoTesto d’esame

06 07 15 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 2015.07.06 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. 1 Scheme 1.1 Closures (6 points) Consider this code: (define (producer ag1 ag2) (let loop ((i 1)) (if (< i 10) (begin ((if (odd? i) ag1 ag2) i) (loop (+ i 1))) (cons (ag2 ’end) (ag1 ’end))))) Define two closuresclos1 and clos2 for passing them toproducer such that it returns the list’(20 9 7 5 3 1) (note that 20 = 2 + 4 + 6 + 8 ). 1.2 Macro (6 points) Define a macro multiple-apply, (multiple-apply (fun-1 fun-2 ...) to list-1 list-2 ...) where fun-i are functions and to is a keyword, which returns a list containing the result of applying fun-i to list-i. E.g. > (multiple-apply (+ - *) to ’(1 2 3) ’(3 4) ’(9 -2)) (6 -1 -18) 1 2 Haskell 2.1 Split (5 points) Assume this is a possible Haskell variant of producer in Exercise 1, in which the closures’ states are made explicit. producer ag1 ag2 = prod’ ag1 [] ag2 0 1 where prod’ ag1 st1 ag2 st2 i | i >= 10 = (st2:st1) prod’ ag1 st1 ag2 st2 i | odd i = prod’ ag1 (ag1 i st1) ag2 st2 (i+1) prod’ ag1 st1 ag2 st2 i | even i = prod’ ag1 st1 ag2 (ag2 i st2) (i+1) 1. Define two suitable functions for producer’s two arguments, such that its call returns [20,9,7,5,3,1]. 2. Write the type of prod’, assuming that all the numbers have type Int. 2.2 Duo-fold (6 points) Define an higher-order function called duofold, which takes two binary functions f and g, a starting value t and a (finite) list [e1, e2, . . .], and returns . . . f(g(f (t, e1), e2), e3), .... Please, write also its type. Example: duofold (+) (-) 0 [1,2,3,4] returns −2 (i.e. 0 + 1 − 2 + 3 − 4). 3 Prolog 3.1 Check…

Anteprima

Prima pagina del documento.

Prima pagina: 06 07 15 1