Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CMPSC 461 Penn State University

Programming Language Concepts Assignment #4

Spring 2012 Due: 10 February

The purpose of this assignment is to gain some experience working with scope and names. You must submit your solution as an attachment to the Angel Drop Box. 1. (10 pts) Consider the following programs written in a C-like language. For each program, explain what it prints out if the language uses (i) static scoping and (ii) dynamic scoping. Give your reasoning in each case. int x = 5; int y = 7; int z = 9; int f1(int a) return a * } int f2(int x) return 2 * } { x; { f1(x); int x = 2; int y = 3; int z = 5; void f1(int a, int b, int c) { print a + x; print b + z; } void f2(int x, int y, int a) { print x * y; f1(a, x, z); } f2(x, z, 3); f1(x, x, y); 2. (10 pts) (a) Consider the following two Scheme expressions (let ((x1 e1) (x2 e2)) e) (let* ((x1 e1) (x2 e2)) e)

print f1(y) + f2(z);

in which e1 and e2 are arbitrary expressions. Under what circumstances are these two expressions equivalent? When are they inequivalent? Give a convincing argument, referring to the semantics (scope) of names. (b) Consider the following two Scheme expressions (let* ((x1 e1) (x2 e2)) e) (let* ((x2 e1) (x1 e2)) e)

in which e1 and e2 are arbitrary expressions. Under what circumstances are these two expressions equivalent? When are they inequivalent? Give a convincing argument, referring to the semantics (scope) of names.

3. (10 pts) Give an example Scheme function that works properly, but would not work properly if Scheme used static typing. Explain why it would not work properly. 4. (10 pts) Give a Scheme expression whose value would be dierent if Scheme used dynamic scoping rules. You will need to dene some functions that your expression calls. 5. (10 pts) Using only those features of Scheme that weve covered in class, does Scheme support overloading of function names? If yes, explain how and when the overloading is resolved. If no, explain why you think Scheme does not support it, based on principles weve discussed.

You might also like