This is the archived website of SI 413 from the Fall 2012 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.
Use a separate sheet of paper for your answers! Everything should be submitted in one packet, all printed out for me to see.
This program is written in pseudocode that's sort of a cross between Python and Javascript. Hopefully the meaning of the syntax is straightforward; if not, ask!
def account(a): def withdraw(x): if a < x: return False else: a = a - x return True return withdraw # Notice a function is being returned! var A = account(10) var B = account(12) print A(11) print B(11)
This one looks like C++:
int x = 10; int i = 5; int foo(x) { if (x == i) { return 3; } else { int i = x - 1; int j = foo(i); return 3 * j; } } cout << foo(3) << endl;
Draw the abstract syntax tree (AST) for Program A above.
Give an example of a program in our spl
language from labs that will have a different result under dynamic scoping vs. lexical scoping.
Show the program and indicate what the result will be in each case.
(Your examples do not have to be very complicated, but they should be unique - I want you to come up with your own!)
Trace the execution of Program B above using dynamic scoping implemented with a Central Reference Table (CRT). In what you turn in, show what the CRT looks like at the time when the stack of bindings for x
has exactly 3 values in it.
Be sure to clearly indicate what is printed as the result of the entire program.