CS 541 Lecture -*-Outline-*- * Bindings (Ch. 4) -- allow "value implementation independence" -- abbreviation ** Bindings and Environments (4.1) Environments can also be interpreted as functions; the same "set of bindings" is looked at as in the other way. Q: Why do we say "bind n to 7" instead of "bind 7 to n"? Another term: "n denotes 7". ** Bindables (4.2) Q: Is there any reason for Pascal to prohibit binding identifiers to record values in constant definitions? (not constant?) ** Scope (4.3) Q: Do names have scope? No, only declarations! *** Block Structure (4.3.1) Q: What is a block? Q: What kind of block structure does C/C++ have? *** Scope and Visibility (4.3.2) Q: What is a binding occurrence? an applied occurrence? Shadowing is another name for "making invisible" (hiding). CLU is one language that prevents redeclaration of identifiers when that would hide existing ones. Q: What are the advantages/disadvantages of this? *** Static and Dynamic Binding (4.3.3) Q: Do you know any language with dynamic binding? (Unix shell, TeX, APL, older LISPs) Q: Can you have static type checking and dynamic binding? ** Declarations (4.4) Elaboration of declarations comes from Algol-68, perhaps Ada; it's used in Ada. Q: What does elaboration of a declaration do? *** Definitions (4.4.1) Definition ONLY produces a binding. In C there is a notion of declaration AND definition. How do they correspond to Watt's ideas? (C definitions give a name a value and a type; C declarations give a name and a type) *** Type Declarations (4.4.2) A definition binds an identifier to an existing type. Q: Why is this true only in languages with structural equivalence? Q: Is a C/C++ typedef a type definition or a newtype declaration? Why? Q: Is the ML idea of giving programmers control over the type newness a good one? *** Variable Declarations (4.4.3) Q: What is the difference between a variable definition and a value definition? A variable definition makes an alias. Q: How is this written in C++? New-variable declarations are the usual variable declarations. Q: What do you think of the ML treatment of variables? *** Collateral Declarations (4.4.4) -- enforce independent elaboration, no interference (example 4.11 in ML) Q: How does this add flexibility? *** Sequential Declarations (4.4.5) Q: In a declaration D1;D2 , can the bindings in D2 override (redefine) those in D1? *** Recursive Declarations (4.4.6) Q: Do you think ML allows non-recursive type definitions? What's the use of non-recursive declarations? Give example of recursive constant declaration (list) *** Scopes of Declarations (4.4.7) What are the scopes of -- type (struct, typedef) from end to end of block -- const (in C++) from end to end of block -- function declarations in C? from beginning to end ** Blocks (4.5) This is terminology from Algol-60. (block has declarations, a compound statement does not) *** Block Commands (4.5.1) (decls begin C end) Q: Do C/C++ have a block command? (yes) Q: Watt assumes that having declarations close to point of first use is good. Is it? Why? Q: Why did Wirth, who knew Algol-60, leave out block commands? (perhaps to simplify the compiler) *** Block Expressions (4.5.2) Q: In LISP and Scheme what do block expressions look like? What are the collateral, sequential, and recursive forms? *** The Qualification Principle (4.5.3) Q: Why are block declarations useful? Q: How do they help satisfy the qualification principle? Q: Are there block declarations in C/C++? Q: Are there any other instances of the qualification principle that would be useful?