TOPICS FOR THE COP 4020 EXAM on Declarative Programming Techniques $Date: 2008/11/03 22:46:25 $ This exam covers topics from homework 3, including declarative programming techniques. It is related to all the course objectives, but especially to [UseModels]. REMINDERS The exam will be open book, open notes. (Warning: don't expect to learn the material during the exam, you won't have time! A good idea for studying is to condense your notes to a few pages of ready reference materials. We suggest that you memorize the Oz syntax you'll need.) If you need more space, use the back of a page. Note when you do that on the front. Before you begin, please take a moment to look over the entire test so that you can budget your time. Clarity is important; if your programs are sloppy and hard to read, you may lose some points. Correct syntax also makes a difference for programming questions. When you write Oz code on this test, you may use anything in the declarative model (as in chapters 2-3 of our textbook), so you must not use cells and assignment in your Oz solutions. (Furthermore, note that the declarative model does not include the primitive IsDet or the library function IsFree; thus you are also prohibited from using either of these functions in your solutions.) But please use all linguistic abstractions and syntactic sugars that are helpful. You are encouraged to define functions or procedures not specifically asked for if they are useful to your programming; however, if they are not in the Oz base environment, then you must write them into your test. You can use the built-in functions in the Oz base environment like Append, Filter, Map, and FoldR. HINTS If you use functions like Filter, Map, and FoldR whenever possible, you will have to write less code on the test, which will mean fewer chances for making mistakes and will leave you more time to be careful. In the "follow the grammar" problems the examples may be very extensive and take a long time to read if you read them all. But the basic idea of the recursion is usually clear from the description, simple examples, and the "follow the grammar" idea of recursing everywhere possible. So look to the examples to confirm your understanding and don't spend time reading examples after you understand the problem. READINGS Read chapter 3, sections 3.1-3.9 of van Roy and Haridi's "Concepts, Techniques, and Models of Computer Programming" (MIT Press, 2004). Also read the "Following the Grammar" handout and be sure to get the comments from our grading of your homework. You can also see our solutions from webcourses. If you have time, study the relevant examples form the Code examples Web page. Also if you have time, and try the old exams (but note that some problems that are relevant to this exam were on Exam 3 in other semesters). Also see the course web site and also the course syllabus for other readings. TOPICS In the following, I use + to denote relatively more important topics, and - to denote relatively less important topics. Topics marked with ++ are almost certain to be on the exam. All of these are fair game, but if you have limited time, concentrate on the ones that are more important first (and in those, the ones you are most uncertain about). SKILLS [UseModels] [Concepts] [MapToLanguages] + Oz programming; be able to: ++ Write iterative functions on integers and lists [HW3: iterative factorial, iterative SumList] (Fall07: MinElement, SumSquares; Spring08: SumValues tail recursion) + Know when to use (or not use) tail recursion to write iterative functions. - Convert a fully recursive function into one that uses tail recursion. ++ Write functions that work on (finite) lists (following the grammar) [HW3: DeleteAll, DeleteSecond, SetOps, Associated, Borrowers, Borrowed, NumBorrowed, CommaSeparate, OnSeparateLines] (Fall07: TeamSpirit, EvenNumbers; Spring08: VoteFor, Positive) ++ Write functions that implement the operations of some declarative ADT. [HW3: SetOps, Possibly Infinite Sets (PISet)] ++ Write functions that work on a given grammar, following the grammar, even if the grammar is previously unknown to you and for which you have never seen examples. [HW3: ShrinkTo on the WindowLayout grammar] [HW3: BEval on the BExp grammar] [HW3: AllIds and SubstIdentifier on the Statement and Expression grammar] [HW3: SumTree and MapTree on a tree grammar] [HW3: TypeOf on an expression grammar] (Fall07: TeamSpirit, EvenNumbers on list grammar, ChangeChannel on WindowLayout grammar, EvalExp on a new expression grammar, ChangeAddress on SalesData grammar, FreeVarIds on the one-argument lambda calculus grammar; Spring08: VoteFor and Positive on list grammar, NegateIfs on the statement expression grammar, Transpose on a new grammar for "music") + Oz programming; be able to: ++ Write functions using for loops (with collect:). [HW3: Associated, Borrowers, Borrowed, NumBorrowed] ++ Write functions using Oz library functions such as Map, Filter, FoldR, All. [HW3: Associated, Borrowers, Borrowed, NumBorrowed, IsFunction] [HW3: MyAppend, DoubleAll, and MyMap using FoldR] (Fall 07: MinElement, SumSquares using FoldR; Spring08: Positive elements in a list of numbers using FoldR, FilterThenMap that filters a list and maps over it also) + Know when to use Oz library functions (especially Map, Filter, and FoldR) and for loops. [HW3: Associated, Borrowers, Borrowed, NumBorrowed, BRelCompose] (Spring08: Positive elements in a list of numbers using FoldR, LazyLanguages filter on a database using for loops) + Curry a given function (make a curried version of it). (Spring08: Curry2 for currying a 2 argument function) + Be able to use a curried function to accomplish some task. - Uncurry a given function. ++ Write curried, higher-order functions that satisfy some specification. [HW3: Compose a list of functions] [HW3: Possibly Infinite sets (PISet)] (Spring08: Curry2 for currying a 2 argument function) ++ Write higher-order abstractions of other functions, and use the abstraction to define the original other functions [HW3: SeparatedBy as abstraction of CommaSeparate and OnSeparateLines] [HW3: FoldTree as abstraction of SumTree and MapTree] + Use functions embedded in data to implement a specification. [HW3: Possibly Infinite sets (PISet)] TERMS AND CONCEPTS [Concepts] [MapToLanguages] [EvaluateModels] You should be able to explain and use (in problems or essays) the following concepts (with appropriate comparisons to related concepts). You should be able to give examples of these concepts. + following the grammar + Read a BNF grammar for a data structure. + Decide whether code (in Oz) follows a given grammar. [HW3: following grammar for lists] + declarative model semantics + When is declarative programming useful? + How is declarative programming defined? + What is a difference list? + What are difference lists useful for? What are their limitations? + declarative model and higher-order functional programming + What is a closure? + What is a higher-order function? + What is a curried function? + Abstract Data types + How is an ADT different from a data type specification? + What is an invariant property of data? + What problems related to the security of ADTs do we need to prevent? + Why prevent them? How could we prevent them? - Why are read-only views needed in the declarative model? + Modules + What is a module? What is it like in C, C++, and Java? + What is a functor? What is it like in C, C++, and Java? - How are modules linked in Oz?