Sooner or later you are going to type a long expression into ML, maybe half a page of function definition, and its not going to be right. Your not going to want to type it all in again are you? The ML mode for Emacs allows you to edit your ML in one window while the ML interpreter runs in another. You then use Emacs commands to send selected parts of your code to the interpretor. Learning how to do this may just save your fellow students from a hideous death; because if you don't, you are quite likely to go postal at some point in the course.
If I had the permissions on the HPC machines it would all be set up for you, but I don't so it isn't. To enable the ML mode for emacs just add the following lines to your .emacs file - or create a .emacs file with the following lines if you don't already have one.
(setq load-path (cons "/home/dcs/jdg659/pub/mosml/utility/sml-mode-3.3b/" load-path)) (autoload 'sml-mode "sml-mode" "Major mode for editing ML programs." t) (setq auto-mode-alist (append '(("\\.sml$" . sml-mode) ("\\.sig$" . sml-mode) ("\\.ML$" . sml-mode)) auto-mode-alist)) (autoload 'sml-mosml "sml-mosml" "Set up and run Moscow ML." t) (defun my-sml-setup () "Initialise SML mode." (require 'sml-font) (setq sml-mode-info "/home/dcs/jdg659/pub/mosml/utility/sml-mode-3.3b/sml-mode.info")) (add-hook 'sml-load-hook 'my-sml-setup) (defun my-mosml-setup () "Initialise inferior SML mode." (setq sml-program-name "mosml") (setq sml-display-frame-alist nil)) (add-hook 'inferior-sml-load-hook 'my-mosml-setup)
After starting Emacs you can place the current buffer in ML mode by typing `M-x sml-mode (OK, its actually called SML mode because it is specific to Standard ML, but lets not fixate on that). Alternatively, if you are editing a file with the extension `.sml', `.sig', or `.ML', then the buffer will automatically be placed in ML mode. For the sake of simplicity you should keep all your ML code in files with a `.sml' extension.
Use Emacs now to edit a file called `ex2.sml'. This should place Emacs in ML mode. Once in ML mode there should be an extra menu available with the heading `SML'. You can now start ML by choosing `Start default ML compiler' from the `Process' menu under `SML'. This creates a new buffer for interacting with ML, in this case called `*mosml*' because that is the name of the executable. You can flip to this buffer at any time with C-c C-s, if the buffer is not visible in some frame a new frame will be created. Try that now.
You can interact with a buffer connected to the ML system exactly as you would with an ML system you started from a terminal. For example, type the following definition into the `*mosml*' buffer.
Obviously, this definition is wrong, but fortunately it is easy to fix. Use the cursor keys to move the cursor back up to where you typed in the definition and fix it. When you hit Enter the revised line with be sent to the ML system again.
val one = 0;
This style of interaction is fine when you are issuing short - one
line - commands, but when you are working on bigger things a different
style of interaction is called for. It is usual to develop an ML
program in one buffer and to transfer parts of it into the ML system
as they are ready to be checked. You can transfer a region of ML code
to the interpreter by selecting the region, for example by dragging
over it with mouse-1, and then typing C-c C-r. Try
this now by writing in the buffer for ex2.sml a function
inc to increment a number, and then transferring the the
definition to the ML system. Check that the definition and transfer
worked correctly by evaluating `
You can learn more about how to interact with ML effectively though Emacs by inspecting the `SML' menu and reading the SML mode information available through that menu.