TOPICS FOR THE COP 4020 EXAM on Declarative Programming Techniques and Declarative Concurrency $Date: 2008/03/27 04:02:29 $ This exam covers topics from homework 3 (problems 12-24) and homework 4 (problems 1-7), including the declarative concurrent model, the demand-driven declarative concurrent model, related programming techniques in Oz, and their relation to Java (and to a limited extent, to C#, C++, and C). This exam 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 concurrent model (as in chapters 2-4 of our textbook), so you must not use cells and assignment in your Oz solutions. (Furthermore, note that the declarative concurrent 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. (This means you can use functions in the Oz base environment such as Map, FoldR, Filter, Append, etc.) READINGS Read chapter 3, sections 3.5-3.9 (concentrating on sections 3.6-3.7), and chapter 4, sections 4.1-4.4 of van Roy and Haridi's "Concepts, Techniques, and Models of Computer Programming" (MIT Press, 2004). If you have time, review the first part of chapter 3 for background, read the rest of chapter 4 for more applications of the ideas, and 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). (Some of the relevant problems from older exams were done in Haskell, which has a different type notation than the one used in class for Oz. See section 4.7 of the text, or go to haskell.org for more about Haskell.) SKILLS [UseModels] [Concepts] [MapToLanguages] + 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) + Know when to use Oz library functions (especially Map, Filter, and FoldR) and for loops. [HW3: Associated, Borrowers, Borrowed, NumBorrowed, BRelCompose] + Curry a given function (make a curried version of it). + 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)] ++ 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)] + Give the output of an Oz expression involving threads + Use both the declarative concurrent model and the declarative model in one program to solve a problem. + dataflow variables: + Use dataflow variables to help with programming with threads; e.g., to automatically determine order of calculations, or to return results or synchronize. [HW4: Order-determining concurrency] (Fall 07: give output of program with threads, Wait, Show) + Explain how to implement dataflow variables in Java [HW4: Threads and dataflow in Java] (Fall 07: concurrency, dataflow, synchronization in Java) + synchronization: + Make one thread wait for another. [HW4: The Wait operation] - Write a barrier synchronization procedure. + Explain how dataflow variables affect execution orderings [HW4: Order-determining concurrency] [HW4: Dataflow behavior in a concurrent setting] + How is synchronization done in Java? How could you use that to simulate Oz's dataflow variables? [HW4: Threads and dataflow in Java] (Fall 07: concurrency, dataflow, synchronization in Java) + stream-based programming: + Write programs using a producer-consumer architecture. [HW4: Approximations, SquareRoot, RelativeSquareRoot, Differentiate] - Use a bounded buffer to help with flow control. - Implement a bounded buffer - Use streams to implement circuit simulations. - Fix deadlocks from feedback in a stream-based system 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. + 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? + Declarative concurrent model + Threads: + What new features are added to the declarative model to support concurrency? + Given a sample program, say what possible orders of execution follow the causal order. [HW4: Thread Semantics, Order determining concurrency] + How are threads modeled in the operational semantics? - How is garbage collection affected by threads? - What happens when there is an unhandled exception in a thread? + Semantic concepts + What is interleaving? [HW4: Thread Semantics] + What is a race condition? [HW4: Threads and dataflow in Java] - What is the causal order? + What is observable nondeterminism? - What is partial termination? + What is the formal definition of declarative concurrency? + What is a stream? How would it be implemented? - What are coroutines? Why are they hard to use? + How is a dataflow variable like a communication channel? + What are dataflow variables good for? [HW4: Threads and dataflow in Java] + Comparison among styles of programming: + What makes a model or style of programming declarative? + What does declarativeness have to do with referential transparency? + Is programming with state declarative? Why or why not? + Can a program that uses state be declarative? + What are two ways to read a declarative program? + Why is declarative concurrency useful? + Why is the declarative concurrent model simple to reason about? (Fall 07: ByNeed and declarativeness, cells and reasoning in Oz) + What are the advantages of declarative programming? + Can we do everything efficiently with the declarative model? What can't be done efficiently? + What problems are hard to modularize in the declarative model? + Is the real world declarative? + What is the difference between declarative and imperative programming?