← Indietro
EsameEsame completoTesto d’esame

25 07 14

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 Exam of 2014.07.25 Notes Total available time: 2h. You may use any written material you need. You cannot use computers or phones during the exam. GIVEN NAME _______________________ SURNAME _______________________ SIGNATURE _______________________ Scheme Exercise 1.1 (4 points) Define a procedure (called vecstrings) that accepts two parameters: a vector V and a list L of strings. vecstrings is used to put every string s in L in V , depending on its length: s is placed at position V[|s|], while strings too long are discarded. If more than one strings have the same length, they are collected in a list. Example: (define ex '("hi" "there" "have" "an" "interesting" "day")) (define v1 (make-vector 7 #f)) (vecstrings v1 ex) is the vector #(#f #f (“an” “hi”) “day” “have” “there” #f) (define (vecstrings V strls) (let ((top (- (vector-length V) 1))) (for-each (lambda (s) (let ((sl (string-length s))) (when (<= sl top) (vector-set! V sl (let ((old (vector-ref V sl))) (cond ((string? old) (list s old)) ((list? old) (cons s old)) (else s))))))) strls) V)) Exercise 1.2 (6 points) Define the procedure make-vecstring, which is a variant of vecstrings returning a closure over V . Such closure has one parameter that must be a string s and works like vecstrings, by putting s in V . When the closure is called with the parameter 'return, it must return the current value of V . Example: (define my-v (make-vecstring v1)) ; the definition of v1 is in Ex. 1.1 (my-v "another") (my-v "member") (my-v "no") (my-v 'return) is the vector #(#f #f (“no” “an” “hi”) “day” “have” “there” “member”) (define (make-vecstring V) (let ((top (- (vector-length V) 1))) (lambda (s) (if (eq? s 'return) V (let ((sl (string-length s))) (when (<= sl top) (vector-set! V sl (let ((old…

Anteprima

Prima pagina del documento.

Prima pagina: 25 07 14