CS 541 Lecture -*-Outline-*- * Abstraction (Ch. 5) ** Kinds of Abstraction (5.1) Abstraction has two main manifestations -- abstraction by specification (how vs. what) -- abstraction by parameterization (specific vs. general) *** Function Abstractions (5.1.1) Q: What kind of thing does a function abstract? Q: In C/C++ one writes return instead of assigning to the procedure name (as in Pascal). Is this less error-prone than Pascal? (compare with ML) Q: Is there any advantage to having separate function expressions (as opposed to just function definitions)? Orthogonality *** Procedure Abstractions (5.1.2) Q: What kind of thing does a procedure abstract? *** The Abstraction Principle (5.1.3) (Landin, Strachey, Tennent) It is possible to construct abstractions over any syntactic class. Q: In what ways does C++ extend C to satisfy the abstraction principle? -- has selector abstractions (abstract var refs) -- has generic abstractions (templates) ** Parameters (5.2) Q: What is Watt's distinction between an actual parameter and an argument? Q: In C, what sorts of values cannot be used as arguments? What bindables don't have values? Q: What is a parameter mechanism? We now turn to a survey of parameter mechanisms... *** Copy Mechanisms (5.2.1) These allow for values to be copied into and/or out of an abstraction when called. -- formal parameter is local variable -- actual argument is copied into it E.g., call by value, call by result, call by value-result. Q: Which does C have? Ada? *** Definitional Mechanisms (5.2.2) The formal parameter is bound directly to the argument (as if by a definition outside the body). -- const (argument is value, formal is const) -- variable (reference) (arg is variable ref, formal is variable) -- note: makes an alias if argument is visible -- procedure & function Q: What is the advantage of constant parameters vs. value parameters? **** Comparison Q: What would make a designer pick copying mechanisms over definitional ones, or vice versa? *** The Correspondence Principle (5.2.3) (between declarations and parameters) Q: Does the redesign of Pascal (Table 5.2) help? How? Q: Does C/C++ comply? ** Evaluation Order (5.3) This is not so much an issue of left to right vs. right to left, but whether to evaluate parameters before or after a call. Q: When are parameters evaluated in eager, normal, and lazy evaluation? Q: Which of these is most like macros? Work Exercise 5.12(b) Q: If we had normal order or lazy evaluation, could we do away with macros? (TALK ABOUT NORMAL VS. TEXT) Lack of side effects is necessary for the Church-Rosser property (why?) But it is not sufficient. For example, a language with a choice primitive (1 || 2) -> 1 or (1 || 2) -> 2 can violate the Church-Rosser property. -- double(1 || 2) -> 2 or 4 under eager evaluation, but 2, 3, or 4 under normal Q: What is a name parameter?