Oz (Mozart)
Oz was designed by Gert Smolka and his students at Saarland University in the early 1990s, and later developed by Peter Van Roy and colleagues. It was built to hold many paradigms in one small kernel language. It is best known through the textbook Concepts, Techniques, and Models of Computer Programming, which uses it to compare paradigms. Mozart is the implementation.
Paradigm: Object-Functional and Beyond
What Makes Oz (Mozart) Special
- A multi-paradigm kernel. A small core language supports functional, object-oriented, logic, constraint and concurrent styles. Each paradigm is a way of using the same core, not a separate sublanguage.
- Dataflow variables. A variable can be created unbound and given its value later, once. Any code that needs the value waits until it is bound. This makes concurrency simple and deterministic.
- Cheap threads.
thread ... endstarts a lightweight thread, and dataflow synchronizes threads with no locks. - Lazy evaluation on demand. A function marked
lazycomputes values only when needed, which makes infinite lists possible. - Objects and ports. Classes give object-oriented programming, and ports (message queues) give actor-style concurrency.
- Constraints and search. Finite-domain constraint programming and a search engine let you state a problem and let the system find solutions, as in logic programming.
Example: Functions, dataflow threads, laziness and a class
declare
fun {Fact N} % functional
if N == 0 then 1 else N * {Fact N-1} end
end
{Browse {Fact 10}} % 3628800
declare X Y
thread Y = X + 1 end % waits until X is bound
X = 41
{Browse Y} % 42
declare
fun lazy {From N} N|{From N+1} end % an infinite list, computed on demand
Xs = {From 1}
{Browse {List.take Xs 5}} % [1 2 3 4 5]
declare
class Counter % object-oriented
attr n:0
meth inc() n := @n + 1 end
meth get($) @n end
end
C = {New Counter inc()}
{C inc()}
{Browse {C get($)}} % 2
How It Works
- Calls are written with braces:
{Fact 10}.{Browse X}shows a value in the Mozart browser window. - The thread starts before
Xhas a value and suspends onX + 1. WhenX = 41runs, it wakes up and bindsYto 42. No lock or callback was needed. Fromlooks infinite, but because it islazy, only the first five cells are built byList.take.- In
Counter,@nreads an attribute and:=assigns it.{New Counter inc()}creates the object and sends it the firstinc()message.
History and Where It Is Used
Oz is mainly used in teaching and research. It shows how paradigms relate: dataflow concurrency, message passing and shared state are all expressible in the same kernel. Few production systems use it, but its ideas influenced later work on concurrency and on multi-paradigm design, and the book that uses it is widely cited. Prism has no Oz grammar, so the example above is not colour-highlighted.