Software for CSE 340
Note: if you have trouble with any of the software on this page,
send mail to me immediately. Remember, we'll have a lab session on Thursday,
Jan 15 in the Towne PC lab, for questions about O'Caml installation.
Writing O'Caml programs
I strongly suggest that you use Emacs to edit your
programs for this course. Emacs is a highly configurable editor, and you
may set it so that it will assist you in developing ML programs that match
the style guide. Emacs is installed on
the lab machines and part of many standard distributions of Linux. If you
would like to install a windows version of Emacs, I suggest the native version
of XEmacs.
- To start emacs
- Windows: Start -> Programs ->Text editors -> emacs 20.7
- Linux: Programs -> Applications -> XEmacs
- Install Tuareg mode for
Emacs
- Download source files.
- Extract them to a directory called emacs in your home directory.
- Put the following lines in a file called .xemacs (or _emacs if on Windows)
in your home directory:
- (setq load-path
(cons (expand-file-name "~/emacs/tuareg-mode-1.41.2") load-path))
- (setq auto-mode-alist (cons '("\\.ml\\w?" . tuareg-mode) auto-mode-alist))
- (autoload 'tuareg-mode "tuareg" "Major mode for
editing Caml code" t)
- (autoload 'camldebug "camldebug" "Run
the Caml debugger" t)
- If you have not used Emacs before, you should go through the tutorial.
- Emacs Manual
Testing Tuareg Emacs mode:
- Start emacs.
- Save the file called nucleic.ml to your machine and load it with Emacs.
- Ensure that the status line at the bottom of the screen says "Tuareg Font"
- Ensure that keywords are colored. The comments at the beginning of the
file should be a different color.
- Add spaces to the begining of a line with code, and ensure that TAB returns
it to the correct place.
Installing O'Caml
O'Caml is installed on both the windows and linux machines in the labs. You
may also download and install it on your own computer.
Compiling and Running O'Caml programs
There are two ways to run O'Caml from within Emacs/XEmacs.
- Toplevel - C-c C-s or Menu: Tuareg -> Interactive Mode -> Run Caml Toplevel
- The toplevel allows you to type in O'Caml expressions and get their results
immediately. This is useful for short programs, and to see what the values
of intermediate expressions are.
- The # indicates a command line.
- For example, if you type "2 + 3;;" (note
2 semicolons at the end!) and press enter, it
replies
with
- :
int
=
5.
- Typing "let x = 2 + 3 ;;" binds the result of the addition to the variable
x, so that you can refer to it later. Then you can type "x + 4;;"
- Typing "#use nucleic.ml;;" loads the file into the interpreter
as if you had typed it. The types of all of the definitions in the file
are printed for you.
- In depth information
- Batch Compilation (This is what you will use most often.)
- Type Esc-x shell (or Menu: Tools -> Shell -> Shell ) to start a shell
in emacs
- At the command prompt, cd to the directory where nucleic.ml is stored.
- Type "ocamlc -o nucleic
nucleic.ml" to create an executable called nucleic.
- Run your program with "./nucleic"
- The nitty
gritty about ocamlc
01/12/2004 4:10 PM