Back
ExamFull examExam paper only

25 07 14

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: 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

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 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

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 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…

Preview

First page of the document.

First page: 25 07 14