COP 4020 Lecture -*- Outline -*- * Introduction to Programming Concepts (Chapter 1) Based on Peter van Roy and Seif Haridi's book, "Concepts, Techniques, and Models of Computer Programming" (MIT Press, 2004), where all references that are not otherwise attributed are found. ------------------------------------------ SELF-TEST FOR CHAPTER 1 System [UseModels] What are the important points for working with the Mozart/Oz system? Variable [Concepts] What does a "variable" mean in Oz? Function defs, Recursion [UseModels] The Fibonacci function is defined by Fib(0) = 1 Fib(1) = 1 Fib(n) = Fib(n-1) + Fib(n-2), if n >= 2 Write this in Oz. Correctness [Concepts] [UseModels] Prove that your Fib function is correct. Lazy evaluation [Concepts] [UseModels] Make Fib run in time O(n). Lists, Pattern matching [UseModels] Write a function Assoc that takes a list of key-value pairs and a key K, and returns the element in the list associated with K, if any. Higher-order functions [Concepts] [UseModels] Write a function Map that takes a function F and a list Lst and returns the list of the results of applying F to each element of Lst, in order. Threads [Concepts] How are threads created? Give an example. Dataflow [Concepts] What is a dataflow variable and how is it used? Give an example. Cells [Concepts] How are memory cells created and used? Give an example. Objects [Concepts] [MapToLanguages] How are objects related to functions? Classes [UseModels] Write a class for 2-dimensional points. Nondeterminism and Time [Concepts] [EvaluateModels] Give an example of a race condition. Does this example need to use cells? Atomicity [Concepts] [EvaluateModels] How are locks used to avoid the problems with concurrency and state? Give an example. ------------------------------------------