

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Harvard School of Engineering and Applied Sciences — CS 152: Programming Languages. Control Flow Analysis and Logic Programming.
Typology: Schemes and Mind Maps
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Harvard School of Engineering and Applied Sciences — CS 152: Programming Languages
Consider the following lambda calculus program.
(λf. (f 76) + (f 77)) (λa. a)
(a) Add labels to the program. That is, make it an expression in the labeled lambda calculus of Lecture 22, where every label is unique.
(b) Let e be your labeled lambda calculus program. Write out C[[e]]e, i.e., the set of constraints for the program e. (Hint, you should have 20 constraints in total. In particular, for each of the 3 applications, you should have 4 constraints, 2 for each of the lambda terms in the program.)
(c) Find C∗^ and r∗, the smallest functions that satisfy the constraints you generated in the question above.
(d) Check that your functions C∗^ and r∗^ make sense. That is, if an expression labeled l can evaluate to an expression labeled l′, do you have l′^ ∈ C∗(l)?
(e) Consider adding the expression (let x = e 1 in e 2 )l^ to the language. Define C[[(let x = e 1 in e 2 )l]]e. Try rewriting the program above using one or more let expressions, and make sure that the constraints you generate for the modified program produce the same solution C∗^ and r∗.
(a) Consider the following Prolog program (where [] is a constant representing the empty list, [t] is short- hand for cons(t, []) and [t 1 , t 2 |t 3 ] is shorthand for cons(t 1 , cons(t 2 , t 3 )).
foo([], []). foo([X], [X]). foo([X, Y |S], [Y, X|T ]) :– foo(S, T )
For each of the following queries, compute the substitutions that Prolog will generate, if any. (Note that there is a difference between an empty substitution, and no substitution.) If the query evaluation will not terminate, explain why.
Control Flow Analysis and Logic Programming Section and Practice Problems
(b) Consider the following Datalog program.
bar(a, b, c). bar(X, Y, Z) :– bar(Y, X, Z). bar(X, Y, Z) :– bar(Z, Y, X), quux(X, Z). quux(b, c). quux(c, d). quux(X, Y ) :– quux(Y, X). quux(X, Z) :– quux(X, Y ), quux(Y, Z).
Find all solutions to the query bar(X, Y, Z).
Page 2 of 2