Class 14: Nested Scopes and Declaration Order


Display version (pdf).



Reading (for next class): PLP, Sections 3.5 and 3.6.1


For this homework, you should refer to (and download) the C program ob.c and the Scheme program ob.scm.

  1. Draw the scope tree for the Scheme program ob.scm. You don't have to draw any empty scopes (i.e., scopes with no bindings in them). (Hint: scoping is by parentheses, and local name declarations all use the define keyword.)
  2. Run the Scheme program ob.scm in DrScheme. What value is produced?
  3. Download and compile the C program ob.c, either by typing make ob (no Makefile required!!) or, more directly, with gcc -o ob ob.c. Then run the program by typing ./ob. What value is produced?
  4. These programs seem to be identical in their semantics, although of course the syntax of C and Scheme are different. Both of these languages also use lexical scope. So why do you think they produce different values? (Hint: think about declaration order.)