Exam1S06Hints

Exam1S06Hints - Design of Programming Languages - Spring...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Design of Programming Languages - Spring 2006 First Exam - March 1, 2006 Do any 6 1. (10 pts) Operational semantics in μ Scheme. Given that μ Scheme has both an environ- ment ρ (a map from names to locations) and a store σ (a map from locations to values), provide the semantic judgment for the LETREC , where the ”denominator” is given by a LETREC( a x 1 , e 1 , . . . , x n , e n A , e ) , ρ, σ A ⇓ a v, σ A Hint: Fll the ”numerator”, and make sure you trace the changes in the environments. Solution : see p. 94 of our main textbook. 2. (10 pts) ML Programmimng. Write an ML function insert that takes two arguments, the second being a list of items matching the Frst in type, and that returns a new list with the Frst argument inserted between each of the elements of the second. The Frst argument must not appear either at the beginning or end of the list returned. Examples: - insert 3 [2,4,6,8,10]; > val it = [2, 3, 4, 3, 6, 3, 8, 3, 10] : int list - insert 3 [1]; > val it = [1] : int list - insert 3 [2,4]; > val it = [2, 3, 4] : int list Solution : /* non-tail-recursive */ fun insert x [] = [] | insert x [y] = [y] | insert x (y::(z::w)) = y::(x::(insert x (z::w))); /* tail-recursive */ fun insert x y = let fun aux_insert x [] z = reverse z [] | aux_insert x [y] z = reverse (y::z) [] | aux_insert x (y::(z::w)) res = 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
aux_insert x (z::w) (x::y::res) and reverse [] z = z | reverse (x::xs) ys = reverse xs (x::ys) in aux_insert x y [] end; 3. (10 pts) DataTypes in μ Scheme.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Exam1S06Hints - Design of Programming Languages - Spring...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online