Running Oz

This page is organized as follows:

  1. Running Oz on Olympus
  2. Running Oz on Your Home Machine
  3. Troubleshooting
  4. Advanced Topics

Running Oz on Olympus

The Olympus system is the recommended platform for course work, but the Mozart/Oz system should run the same everywhere, so the choice is up to you.

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 .

Starting Mozart

On olympus Mozart/Oz system is found in /local/gnu/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 Home Machine

The Mozart/Oz system works on a home machine in the same way as on the Olympus system.

Getting Mozart/Oz for your Home Machine

The Oz interpreter used for this course is available on many platforms, including Unix, Macintosh, and Windows. You can download it from mozart-oz.org. Follow the installation instructions carefully, in particular define the OZEMACS variable in your environment if you don't have a program named "emacs" that runs emacs in your PATH. (To set environment variables in Windows XP, 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 is version 20.7, which is old. There are significant advantages to using the latest version, which you can get from ftp://ftp.gnu.org/gnu/emacs/windows/.

Return to top

Troubleshooting

Browse Doesn't Work Under Windows Vista

If you are using Windows Vista, then Emacs and Oz run okay, but older versions of the Windows installer (which now include a fix), the standard release the (the version of) Tcl/Tk that is used by the Oz Browser didn't work. Please download and install again to fix.

If you don't want to install with the new installer, a workaround under Windows Vista is to use Show instead of Browse. If you use Browse, the Tcl/Tk code for the Oz Browser breaks, but the rest of Mozart Oz works fine (it seems). When you use Show, the output appears in the buffer named *Oz Emulator*. You can find that on the buffers menu in Emacs, or use C-x b (that's control-x then the character b) to switch to that buffer in Emacs, so you can see the output. You may find it helpful to have 3 windows open (your file, the emulator, and the compiler), which you can do by splitting the compiler's window using C-x 2 and then switching one of these to show the emulator window as above. (See the Emacs help for more about splitting the window and buffers.)

Showing Strings as Strings Instead of Lists of Character Codes

The following is adapted from http://www.ling.gu.se/~lager/kurser/Programming/Exercises/warmup.htm.

To Browse a string like "foo" and have it display the string as a string in the Browser, in the 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.

\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 you have the files you want to \insert in. 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"}} .

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.

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.

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).

Return to top

Advanced Topics

For some problems in the book, you will 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.

If you would rather do it the hard way, 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)
  (progn
    ;; 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...)
  (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)
			"c:/cygwin/usr/local/mozart/share/elisp"
		        "/local/gnu/share/elisp")))))

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:

(viper-mode)

Return to top

Last modified Monday, March 10, 2008.

This web page is for the Spring 2008 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. 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.