CS374: Programming Language Principles - Binding and Scope
The goals of this activity are:
- To define the various ways that names can be bound to items such as variables
- To explain interpreter or compiler binding of types
- To differentiate between strongly and weakly typed languages
- To define variable scope
- To relate scope to a function call stack
Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.
Model 1: Binding
foo be re-assigned at runtime? Would you say that it is statically or dynamically bound to its value? How about
- Do you think this is true of every language?
- How many bindings are there of the identifier
x is staically bound, it must be resolved by the compiler at compile time. How is the correct value obtained at each reference?
- What would happen if
x is re-declared in
foo after it has already been declared in languages like C and Java that specify and insist on proper types (these are called strongly typed languages)?
Model 2: Tracking Bindings
- What kinds of information are needed to specify a bound symbol?
- What kind of data structure would enable a dynamic number of bound variables in a routine?
- What revisions are needed to support additional data types?
- What revisions are needed to support scope, so that variables of the same name can exist in subroutines?
Model 3: Binding Functions
- How can polymorphism work in a statically bound language? How might this differ from a dynamically bound language?
Model 4: Virtual Inheritance
- A call to
x is of type
Animal but refers to a
Llama, would output what?
- How would this differ if
Eat was not virtual, and implemented in the class
I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.