Introduction to the Code Examples
This page gives access to code examples related to subjects covered in COP 4020 at UCF, as taught by Gary T. Leavens. It does not cover concepts, definitions, proofs, and examples of such that are not embodied in code.
Throughout this index, chapter numbers refer to the course textbook, Concepts, Techniques, and Models of Computer Programming, by Peter Van Roy and Seif Haridi (MIT Press, 2004).
See also the Supplements Web Site for the textbook. On that web site you will find a link to source code for all the book's figures, several supplements to the Mozart system (including a set of basic system supplements to be put in your .ozrc file), and links to other Mozart source code.
The examples presented here are (generally) not found in the book (for those, see above), but originate with the course.
For a reference to Oz's syntax and semantics, see Appendix B and Appendix C of the textbook, and the on-line documentation for Mozart. In particular The Oz Notation defines the language and The Oz Base Environment defines the built-in procedures and functions available on various types of data. This documention also ships with the Mozart installation, and so should be accessible directly from your computer if you have Mozart installed.
Examples
Chapter 1: Introduction to Programming Concepts
1.3: Functions
Write recursive functions on numbers:
ProdFromTo.oz (see also ProdFromToTest.oz)
SumFromTo.oz (see also SumFromToTest.oz)
Count.oz (see also CountTest.oz)
1.5: Functions over lists
Write recursive functions on lists:
Assoc.oz (see also AssocTest.oz)
ListLength.oz (see also ListLengthTest.oz)
Product.oz (see also ProductTest.oz)
1.8: Lazy evaluation
What is lazy evaluation? Given an example.
FibLazy.oz (see also FibLazyTest.oz)
1.9: Higher-order programming
What is higher-order programming?
CAdd.oz (see also CAddTest.oz)
Compose.oz (see also ComposeTest.oz)
1.14: Classes
What is a class?
Toggle.oz (see also ToggleTest.oz)
1.17: Where do we go from here?
What are the features of the relational model?
FourLetter.oz (see also FourLetterTest.oz)
Chapter 2: Declarative Computation Model
2.3: Kernel language
What is a closure? How would you implement a closure in C or C++?
2.6: From kernel language to practical language
How does pattern matching work for function formal parameters?
FunPatMatch.oz (see also FunPatMatchTest.oz)
Chapter 3: Declarative Programming Techniques
3.2: Iterative computation
Write tail recursive functions:
SumFromTo.oz (see also SumFromToTest.oz)
See ProductI in Product.oz (see also ProductTest.oz)
A higher-order abstraction of iteration is found in Iterate.oz (see also IterateTest.oz).
3.4: Programming with recursion
ProdFromTo.oz (see also ProdFromToTest.oz)
3.4.2: Programming with lists
Write recursive functions on lists:
Assoc.oz (see also AssocTest.oz)
ListLength.oz (see also ListLengthTest.oz)
Product.oz (see also ProductTest.oz)
DeleteFirst.oz (see also DeleteFirstTest.oz)
3.4.4: Difference lists
DiffList.oz (see also DiffListTest.oz)
3.4.6: Trees
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.
TreeFuns.oz (see also TreeFunsTest.oz)
Other grammars
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.
See also section 3.4.2.6 and Gary T. Leavens's paper Following the Grammar (UCF CS-TR-07-10a, October 2007).
Naturals.oz (see also NaturalsTest.oz)
Eval.oz (see also EvalTest.oz)
3.6: Higher-order programming
Genericity
Write higher-order abstractions of other functions, and use the abstraction to define the original other functions.
TreeFuns.oz (see also TreeFunsTest.oz)
In the book Iterate.oz (see also IterateTest.oz) is treated in section 3.2.4. There is also an example of currying here (Iterate2c).
Embedding
Use functions embedded in data to implement a specification.
Seq.oz (see also SeqTest.oz)
3.6.2: Loop abstractions
Use FoldR and other higher-order functions to write recursive functions on lists.
FoldRExamples.oz (see also FoldRExamplesTest.oz)
3.6.3: Linguistic support for loops
Use the for loop notation (with collect:):
ForLoopMap.oz (see also ForLoopMapTest.oz)
3.7: Abstract data types
Write functions that implement the operations of some declarative ADT.
See the specification of SampleSecures in SampleSecureTest.oz (see also SampleSecure.oz)
3.7.1: A declarative stack
See the specification of Stacks in StackTest.oz (see also Stack.oz)
3.7.5: The declarative model with secure types
How could we prevent problems related to the security of ADTs?
Stack.oz (see also StackTest.oz)
SampleSecure.oz (see also SampleSecureTest.oz)
Higher-order representations (embedding)
Use functions embedded in data to implement a specification.
Seq.oz (see also SeqTest.oz)
3.9.3: Software components
What is a module? What is a functor?
Combinators.oz (see also CombinatorsTest.oz)
Testing.oz (see also TestingTest.oz, Assert.oz, and Test.oz)
Chapter 4: Declarative Concurrency
4.1: The data-driven concurrent model
Double.oz (see also DoubleTest.oz)
Queue.java (see also QueueTest.java)
4.2: Basic thread programming techniques
4.3: Streams
ForceList.oz (see also ForceListTest.oz)
Hailstone.oz (see also HailstoneTest.oz)
HailstoneMax.oz (see also HailstoneMaxTest.oz)
HailstoneSteps.oz (see also HailstoneStepsTest.oz)
4.3.2: Transducers and pipelines
HailstonePeaks.oz, which uses Hailstone.oz and HailstoneMax.oz (see also HailstonePeaksTest.oz which uses ForceList.oz)
4.3.3: Managing resources and improving throughput
You may want to compare the examples in this section with those in section 4.5.3, which are simpler.
HailstoneDD.oz (see also HailstoneDDTest.oz)
HailstoneBB.oz (see also HailstoneBBTest.oz and BufferDD.oz)
4.3.4: Stream objects
MakeStreamObject.oz (see also MakeStreamObjectTest.oz)
4.4.3: Concurrent composition
Barrier.oz (which is the textbook's figure 4.22) a use of which is in BarrierTest.oz
4.5.1: The demand-driven concurrent model
4.5.3: Lazy streams
LazyLists.oz (see also LazyListsTest.oz.)
HailstoneLazy.oz (see also HailstoneLazyTest.oz.)
Last modified $Date: 2007/11/02 18:09:28 $.