Oz (programming language)

From Wikipedia, the free encyclopedia

(Redirected from Oz programming language)
Jump to: navigation, search
Oz
Paradigm multi-paradigm: logic, functional, imperative, object-oriented, constraint, distributed, concurrent
Appeared in 1991
Designed by Gert Smolka & his students
Developer Mozart Consortium
Typing discipline dynamic
Major implementations Mozart Programming System
Influenced by Prolog

Oz is a multiparadigm programming language, developed in the Programming Systems Lab at Saarland University.

Oz was first designed by Gert Smolka and his students in 1991. In 1996 the development of Oz continued in cooperation with the research group of Seif Haridi at the Swedish Institute of Computer Science. Since 1999, Oz has been continually developed by an international group, the Mozart Consortium, which originally consisted of Saarland University, the Swedish Institute of Computer Science, and the Université catholique de Louvain. In 2005, the responsibility for managing Mozart development was transferred to a core group, the Mozart Board, with the express purpose of opening Mozart development to a larger community.

The Mozart Programming System is the primary implementation of Oz. It is released with an Open source license by the Mozart Consortium. Mozart has been ported to different flavors of Unix, FreeBSD, Linux, Microsoft Windows, and Mac OS X.

Contents

Oz contains most of the concepts of the major programming paradigms, including logic, functional (both lazy and eager), imperative, object-oriented, constraint, distributed, and concurrent programming. Oz has both a simple formal semantics (see chapter 13 of the book mentioned below) and an efficient implementation[citation needed]. Oz is a concurrency-oriented language, as the term was introduced by Joe Armstrong, the main designer of the Erlang language. A concurrency-oriented language makes concurrency both easy to use and efficient.

In addition to multi-paradigm programming, the major strengths of Oz are in constraint programming and distributed programming. Due to its factored design, Oz is able to successfully implement a network-transparent distributed programming model. This model makes it easy to program open, fault-tolerant applications within the language. For constraint programming, Oz introduces the idea of "computation spaces"; these allow user-defined search and distribution strategies orthogonal to the constraint domain.

Oz is based on a small core language with very few datatypes that can be extended into more practical ones through syntactic sugar.

Basic data structures :

  • Numbers : floating points or integer (real integer).
  • Records : for grouping data : circle(x:0 y:1 radius:3 color:blue style:dots)
  • Lists : a simple linear structure :
2|(4|(6|(8|nil)))
2|4|6|8|nil % syntax sugar
[2 4 6 8] % more syntax sugar

Those data structures are values (constant), first class and dynamically type checked.

Functions are first class values, allowing higher order functional programming :

fun {Fact N}
   if N =< 0 then 1 else N*{Fact N-1} end
end

fun {Comb N K}
   {Fact N} div ({Fact K} * {Fact N-k}) % integers can't overflow in Oz
end

fun {SumList List}
   case List of nil then 0
   [] H|T then H+{SumList T} % pattern matching on lists
   end
end

When the programs encounters an unbound variable it waits for a value :

thread 
   Z = X+Y     % will wait until both X and Y are bound to a value.
   {Browse Z}  % shows the value of Z.
end
thread X = 40 end
thread Y = 2 end

It is not possible to change the value of a dataflow variable once it is bound :

X = 1
X = 2 % error

Dataflow variables makes it easy to create concurrent stream agents :

fun {Ints N Max}
   if N == Max then nil
   else 
      {Delay 1000}
      N|{Ints N+1 Max}
   end
end

fun {Sum S Stream}
   case Stream of nil then S
   [] H|T then S|{Sum H+S T} end
end

local X Y in
   thread X = {Ints 0 1000} end
   thread Y = {Sum 0 X} end
   {Browse Y}
end

Because the way dataflow variables works it is possible to put threads anywhere in the program and it is guaranteed that it will have the same result. This makes concurrent programming very easy. Threads are very cheap, it is possible to have a hundred thousand threads running at once.

Computes a stream of prime numbers by recursively creating concurrent stream agents that filter out non prime numbers:

fun {Sieve Xs}
   case Xs of nil then nil
   [] X|Xr then Ys in
      thread Ys = {Filter Xr fun {$ Y} Y mod X \= 0 end} end
      X|{Sieve Ys}
   end
end

Oz uses eager evaluation by default, but lazy evaluation is possible :

fun lazy {Fact N}
   if N =< 0 then 1 else N*{Fact N-1} end
end
local X Y in
  X = {Fact 100} 
  Y = X + 1 % the value of X is needed and fact is computed
end

The declarative concurrent model can be extended with message passing through simple semantics :

declare
local Stream Port in
   Port = {NewPort Stream}
   {Send Port 1} % Stream is now 1|_ ('_' indicates an unbound and unamed variable)
   {Send Port 2} % Stream is now 1|2|_ 
   ...
   {Send Port n} % Stream is now 1|2| .. |n|_
end 

With a port and a thread you can define asynchronous agents :

fun {NewAgent Init Fun}
   Msg Out in
   thread {FoldL Msg Fun Init Out} end
   {NewPort Msg}
end

It is again possible to extend the Declarative model to support state and Object Oriented programming with very simple semantics ; We create a new mutable data structure called Cells :

local A X in
   A = {NewCell 0}
   A := 1  % changes the value of A to 1
   X = @A  % @ is used to access the value of A
end

With this simple semantic changes we can support the whole Object Oriented paradigm. With a little syntax sugar OOP becomes well integrated in Oz.

class Counter
   attr val
   meth init(Value)
      val:=Value
   end
   meth browse
      {Browse @val}
   end
   meth inc(Value)
      val :=@val+Value
   end
end

local C in
   C = {New Counter init(0)}
   {C inc(6)}
   {C browse}
end

  • Alice, the concurrent functional constraint programming language from Saarland University
  • Mercury, a functional logic programming language
  • Scala programming language
  • Dataflow programming

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.