Running Oz

This page is organized as follows:

  1. Running Oz on Eustis
  2. Running Oz on Your Own Machine
  3. Troubleshooting
  4. Advanced Topics

We recommend using the Mozart/Oz system for this class, since it corresponds closely to the van Roy and Haridi book, Concepts, Techniques, and Models of Computer Programming.

Running Oz on Eustis

The system is available for course work, but the Mozart/Oz system should run the same everywhere, so the choice is up to you. (Most students find it much more convenient to use Mozart/Oz from their own machine.)

You can login to your account at using your NID as your login. Your default password is of the form Pyymmdd, where yymmdd is your birth year, month and day.

To access Eustis, use an ssh client like putty from anywhere on campus. From off-campus, you will need a VPN connection to UCF first. For a VPN account and help, go to

Starting Mozart

On Eustis, the Mozart/Oz system is found in /usr/bin/, which should be in your PATH by default. (Thus you shouldn't have to do anything special to set this up.)

To start the Mozart/Oz system, simply issue the command oz at the shell's prompt.

Exiting Mozart/Oz

Mozart runs under Emacs, so to quit, use the File menu, or type C-x C-c.

Return to top

Running Oz on Your Own Machine

The Mozart/Oz system works on a home machine in the same way as on the Eustis system (so see above).

Getting Mozart/Oz for your Own Machine

The Oz interpreter used for this course is available on many platforms, including Unix, Macintosh, and Windows. You can download it from Follow the installation instructions carefully, in particular define the OZEMACS variable in your environment, so that it's value is the full path to the runemacs.exe executable in the Emacs bin directory. Defining the OZEMACS enviroment variable properly is crucial if you don't have a program named "emacs" that runs the emacs editor in your PATH. (To set environment variables in Windows XP/Vista/7, start the control panel, then click on "System", then the "Advanced" tab, then click on "Environment Variables".)

Note, however, that the version of emacs on the Mozart/Oz web page might be old. There are significant advantages to using the latest version, which you should get from

If you have trouble on a MacOS X system, try installing version 1.9 of Aquamacs Emacs. The latest version (2.3a) seems to not work out of the box with Mozart/Oz, because it has a different name ("Aquamacs" vs. "Aquamacs Emacs"). Alternatively you can link the new version under the old name by executing the following commands from a shell:

      cd /Applications/
      ln -s "Aquamacs"
      cd /Applications/
      ln -s Aquamacs "Aquamacs Emacs"

If you are having trouble on a MacOS Snow Leopard system, due to error 126 or a problem that ozengine can't be found, there is a fix for that. The essence is to start a shell, and do the following, after which it should all work:

        cd /Applications/
        mv ozplatform ozplatform.original
        echo '#!/usr/bin/env bash' >ozplatform
        echo 'echo "darwin-i386"' >>ozplatform
        chmod a+x ozplatform

If you are trying run Mozart on a 64-bit Ubuntu system, then you can follow this guide to creating a 32-bit chroot environment, and from there you should be able to follow the instructions on the Mozart site (for instance, using apt-get install mozart for Ubuntu). If it is loading with an error 2, then this site may be of help. Also, if you have a problem with the display, be sure to follow the Debootstrap Chroot guide all the way through (even though "Setting up a dchroot (non-root) environment" seems unnecessary, it is), so you need to set up the display (with export DISPLAY=:0.0). (Thanks to Ryan McConnell for these tips for Ubuntu.)

Return to top


Trouble with the Mozart/Oz install

If you can't get Mozart/Oz to run on your own computer, see the Getting Mozart... section above. In particular set the OZEMACS environment variable to the full path to the emacs executable.

\insert Doesn't Work

If it seems that \insert isn't working for you, then the problem may be that you aren't starting Oz from the same directory as the files live in when you are trying to \insert. This can happen if you start Mozart's OPI (the Oz Programming Interface) from a shortcut that uses a different starting directory.

Here are some fixes, each of which should work, that you can try in order from easiest to more involved:

  1. Start the Mozart OPI by double clicking on a .oz file that is in the directory where your files and the tests are, instead of just starting Mozart. You could just double click on the test file, for example. This will cause the Emacs and Oz current directory to be the directory where the file is.
  2. Change the starting directory in the shortcut from which you start the Mozart OPI to use the directory you have your files and the test files in.
  3. Define the environment variable OZPATH to include the directory in which you have the files that you want to \insert. On Windows this path would be a semicolon (;) separated list of directory names. (To set environment variables in Windows XP, start the control panel, then click on "System", then the "Advanced" tab, then click on "Environment Variables".) You'll have to restart the OPI before this takes effect. You can check what's in your OZPATH environment variable by executing: {System.showInfo {OS.getEnv "OZPATH"}} .

Showing Strings as Strings Instead of Lists of Character Codes

The following is adapted from

To Browse a string like "foo" and have it display the string as a string in the Browser, in the Oz browser window click on Options then on Representation and check the box Strings. Then mark the list of Ints (Chars) and click on Selection then Rebrowse.

To show strings as text in the emulator, instead of using Show, use System.showInfo.

Arity Errors

If you get an error message about "illegal arity in application" or "wrong arity in application", then you have made a mistake either in calling a procedure or function with the wrong number of arguments or in using a procedure call as an expression or a function call as a statement. See ArityError.oz for details.

This can also happen if you think you are writing a function (with an expression in its body) but you use proc, or if you think you are writing a procedure (with a statement in its body) but you use fun.

Illegal Record Label Errors

If you get an error message about "illegal record label" or a runtime "type error" with a complaint from Tuple.make that it expected a literal, then you have made a mistake in your function or procedure calling syntax. See TupleError.oz and TupleError2.oz details.

Unexpected Declare

If you see an error message that there is an unexpected "declare" in our testing files, and included in the message is that Oz was expecting the token T_end (or something similar), then the problem is that your code is missing an "end" (or whatever else Oz was complaining that it was expecting instead of "declare"). The problem is not a problem in our testing files.

Object Application Outside of Method

If you see a (syntax) error message that there is an "expansion error" saying that you have an "object application used outside of method," this means that you used a comma (,) in your program. Note that unless you are using the object-oriented features of Oz, you shouldn't be using commas at all in your code. Actual argument expressions, formal parameters, and list elements are separated by blank space(s), without commas. See ExtraCommas.oz for an example of this error.

Don't see any Output

If you don't see any output from our tests cases after you feed our tests to Oz, it may be because you are looking at the wrong Emacs buffer. (This especially happens when your tests don't throw any uncaught exceptions, i.e., when you haven't made any gross coding errors.) To see the output from our testing files, you must tell Emacs to switch to the *Oz Emulator* buffer. In that buffer you should see the test output. From the Oz menu use Show/Hide then select Emulator. (By default you can also type C-. e to Emacs from an Oz Window.)

Another reason there may be no output is if our tests use Assert, which only produces output if an assertion fails. Look at the testing file to see if this is the case.

Expression at Statement Position

The easiest way to get the error "expression at statement position" from Oz is to write an expression at the top-level of your file and then use "Feed Buffer" or otherwise feed that part of your file to Oz. At the top level, Oz expects statements (roughly speaking, technically they are "queries" in the grammar, which include statements and declare). To fix this, instead of writing an expression like {F 3} at the top level, use Browse or Show, as in {Browse {F 3}} or {Show {F 3}}.

More sophisticated ways to get the error "expression at statement position" sometimes arise from trying to use if-expressions the wrong way, as in the function contained in ExpressionAsStatementError.oz. In this erroneous code, line 4 (marked (1) in the comment) and line 5 (marked (2) in the comment), are considered to be statements by Oz, because the Oz parser looks for a single expression in the body of a function, and because Oz has a sugar for expressions that allows an expression to be a statement followed by an expression. So the parser tries to parse (1) and (2) as statements (so that these two in sequence are a single statement). But an if-statement must have statements in its body, and (1) and (2) have expressions instead of statements in their bodies. This is why Oz complains that it finds expression in statement posiitions at places (1) and (2).

The way to fix ExpressionAsStatementError.oz is to use "else" or "elseif" to connect the different if-expressions into a single if-expression. The moral of this story is to make sure that the body of your function always is a single expression. Connect expressions together to make one large expression.

Solve isn't Loading

If you aren't getting the Solve procedure for chapter 9 to work for you, you need to get it from the textbook's basic system supplements file. This will be loaded automatically if you save it as your .ozrc file in your home directory (or have your .ozrc file load it).

Other Problems

If you are having a problem not described above, or if the solutions listed above are not working for you, you can look at the webcourses discussions, where we often post answers to other people's questions. If none of that help then please don't hesitate to contact the course staff.

Email Tips for Getting Help with Your Programming Problems

If you send an email about a programming problem you are having, please include:

  1. A descriptive subject, such as "My code crashes on COP 4020 HW4, problem 3"
  2. A clear description of what homework problem you are trying to solve, such as "homework 4, problem 3".
  3. A description of your problem's symptoms (e.g., "my code doesn't compile" or "my code gives a arity error").
  4. If your problem occurs at runtime, then include a description of exactly what test inputs are causing your code's problem.
  5. A copy of your code. (It is best if you paste your code into the body of your message, so that staff can read it even on a primitive email reader, like a cell phone.)

Email Tips for Getting Clarifications

If you are just having trouble understanding how to start on a programming problem, then please include:

  1. A descriptive subject (e.g., "Can't understand COP 4020 homework 4, problem 3")
  2. A description of exactly what about problem you find confusing (e.g., "I don't understand what result is supposed to be returned for an empty list, since there are no test cases that show that and the description also doesn't mention this").

If you don't understand how to proceed to start on a problem, then it may be best to see us in person.

Return to top

Advanced Topics

For some problems in the book, you will need the Mozart initialization file, which should be saved as .ozrc in your home directory.

See the Mozart/Oz web site for more about the interface. See also the course resources page for links to more Oz resources.

Windows Keystrokes in Emacs

If you like to use the standard Windows keystrokes for cut, paste, and copy, customize Emacs to use CUA-mode by default. (This assumes that you have Emacs version 22 or later. The one on the Mozart/Oz web page is version 20.7, which is old.) Use the menu "Options", select "Customize Emacs", and from there the select "Top Level Customizations". then select the "Convenience" group by clicking on the "go to group" link, and then go to the Cua group, and click on the "Value Menu" for enabling this customization.

If the above doesn't work, or if you have a version of Emacs previous to 22, put the following in your emacs initialization file, ~/.emacs.el. (The lines that start with a semicolon are comments, and can be omitted.)

(if (< emacs-major-version 22)
    ;; Make emacs more like standard windows applications in terms of
    ;; mouse selections (this is similar to pc-select).
    ;; One advantage is this is that it makes Dragon Dictate work with Emacs.
    (require 'cua)
    ;; Make the behavior of emacs on C-c, C-v, C-x, and C-z to be
    ;; just like that of be as in standard window apps, so you can use
    ;; these keys to copy, paste, and select when there is a selection
    ;; active, then uncomment the following.
    (CUA-mode t)
    ;; Make C-c leave the region active, which is what happens under Windows.
    (setq CUA-mode-keep-region-after-copy t)
  ;; The same for emacs version 22 (and hopefully higher...)
  ;; but not for aquamacs, which already has it.
  (if (not (featurep 'aquamacs))
      (progn (cua-mode)
             (setq cua-enable-cua-keys t)
             (setq cua-mode-keep-region-after-copy t)

Alternatively, you can use Gary Leavens's .emacs.el file which includes the above lines and several other things. It should be saved into .emacs.el in your home directory. (On Windows you may not have a home directory yet, so pick one. You also have to set HOME in the environment; this is automatic in Unix and hence on Mac OS X, but needs to be done by hand in Windows.)

Running Oz from Within Emacs

To run Oz from within emacs, you can use the following lines in your ~/.emacs.el file.

;;; Oz program mode with Mozart/Oz.
;;; You have to arrange for the Oz-related emacs lisp (.el) files
;;; to be in emacs's load-path, for its bin directory to be in the PATH,
;;; and for the OZHOME environment variable to be set properly.
(add-to-list 'auto-mode-alist '("\\.oz\\'" . oz-mode))
(add-to-list 'auto-mode-alist '("\\.ozg\\'" . oz-gump-mode))
(autoload 'run-oz "oz" "" t)
(autoload 'oz-mode "oz" "" t)
(autoload 'oz-gump-mode "oz" "" t)
(autoload 'oz-new-buffer "oz" "" t)

You can get the above code from Gary Leavens's mode-customizations.el file. The above code makes some assumptions; in particular it assumes that the emacs-lisp files for Mozart/Oz are in the emacs load-path. You can add directories to this load-path by putting the following code near the beginning of your ~/.emacs.el file.

(setq load-path
 (cons "~/emacs"
	 (append load-path
		(list (if (eq system-type 'windows-nt)

The above adds the directory where the Mozart/Oz install has these emacs-lisp files to the load-path, depending on the kind of system being used.

See the Mozart/Oz documentation for more bullet-proof emacs customization code that only relies on OZHOME being set properly.

Making Emacs find your Customization File

On Linux machines, it seems that there is no problem getting the oz command to use your ~/.emacs.el file; you just have to have it in your home directory. On Windows machines, if the emacs started by the oz command is not finding your ~/.emacs.el file, it is because it doesn't know where your home directory is. To do this, you have to set your environment variable HOME to the right directory. (If you use cygwin, you can also make a shortcut in a shell script.)

For Vi Users

If you are a vi user, you may want to use viper-mode in emacs to get the vi keystrokes and still use the Mozart Oz Programming Interface. To do this, put the following in your .emacs.el file:


Return to top

Last modified Monday, March 5, 2012.

This web page is for the Spring 2012 offering of COP 4020 at the University of Central Florida. The details of this course are subject to change as experience dictates. You will be informed of any changes. Please direct any comments or questions to Gary T. Leavens at Some of the policies and web pages for this course are quoted or adapted from other courses I have taught, in partciular, Com S 342.