Search

mozart: The Mozart Programming System

January 14th, 2007 edited by ana

Entry submitted by Kari Pahula. DPOTD needs your help, please contribute !

Mozart is an implementation of Oz, a multiparadigm programming language, with a strong support for concurrent and distributed computing and for solving problems involving optimization and inference.

Some of Oz’s distinctive features are single assignment variables and binding. For example, you can do declare A B C and then execute C = A and [A 2] = [1 B] ([] marks a list in Oz) and have A = 1, B = 2 and C = 1 in the end.

Being single assignment variable means that executing A = B would be a runtime error. If needed, you could create new computation spaces where you could safely create condtradictions and examine the failures from outside.

Another one of Oz’s features is transparent support for concurrency. You can try out the next example yourself if you have no aversion towards using Emacs by installing mozart for yourself and feeding it line by line to the emulator. Start the X Mozart programming environment from the menu and go through it line by line and press C-. C-l as you go.

What you type

What you see

declare H W
{Inspect rect(width:W height:H area:thread W*H end)}

rect(area:_ height:_ width:_)

H = 20

rect(area:_ height:20 width:_)

W = 45

rect(area:900 height:20 width:45)

What happens in this example is that the thread started for counting the area suspends until both W and H are bound to a value. Once both are known, the thread continues execution and sets the corresponding field in the rect record.

Any of the above didn’t involve state at all. With Mozart, you can get by quite far within the declarative model itself. But when needed, there are two (equivalent) abstractions available for stateful operations. One is chunks, which operate much like regular variables with destructive updates. The other is ports, which are many-to-one communication channels. If you’re familiar with Erlang, you’d recognize them to be similar to the message passing used in it.

As an example, let’s write an echo server.

declare Echo
local
   Xs P
   {Port.new Xs P}
   proc {Consume Xs}
      X|Xr = Xs  % suspends until a new list item arrives to Xs
   in
      {Inspect X}
      {Consume Xr}
   end
   thread {Consume Xs} end
in
   proc {Echo M}
      {Port.send P M}
   end
end

This is only a small scratch on the surface of what Oz and Mozart can do. Even if you’re not going to start writing programs using Mozart yourself, the concepts behind it are well worth knowing for any self-respecting programmer.

Links

Mozart is available for most 32-bit architectures in Debian Woody, Sarge and Etch. The changes between 1.3.1 and 1.3.2 are relatively minor, so you won’t be missing much if you’re using the version in Sarge. It is also available in Ubuntu since Warty.

Posted in Debian, Ubuntu |

2 Responses

  1. dooglus Says:

    > press C-. l as you go

    That’s “C-. C-l”. “C-. l” doesn’t do anything, at least not on the version currently in debian sid.

  2. kaol Says:

    Thanks for spotting the error. s/C-. l/C-. C-l/ applied to the article.