Installing SML on Windows

This document describes the basic steps for installing SML on a Windows machine for use with TextPad. If you don't have TextPad, you can download it here. First download a recent version of SML from SML of New Jersey. Do not download the self-installing exe for Windows (this is a very old version of SML). You should download a version at least as current as the one on attu (currently version 110.58). When you have selected a version, you will see two files listed under Windows: smlnj.zip and WININSTALL. You can read the WININSTALL instructions, but they are repeated in the following instructions:

  1. Download the smlnj.zip file and use a tool like Winzip to extract the contents to a directory on your system. I'll assume you put it in c:\smlnj.

  2. Define an environment variable called SMLNJ_HOME that points to the directory you extracted SML to. I did this by right-clicking on "My Computer", selecting Properties, selecting Advanced, selecting Environment Variables, clicking on "New" under User variables and using these settings:
            Variable name:   SMLNJ_HOME
            Variable value:  c:\smlnj    
    

  3. If you're just going to use TextPad, you don't need this final step. This is for people who want to open a "Command Prompt" window and run SML from that, but it's not a bad idea to do this anyway. The steps are similar to the previous definition of an environment variable. You need to modify your setting for PATH. You can ignore any system variable for PATH. You want a user variable for PATH. If you don't have one yet, click on "New" under User variables and use these settings:
            Variable name:   PATH
            Variable value:  c:\smlnj\bin
    
    If you already have a PATH setting, edit it and add ;c:\smlnj\bin to the end.

At this point you should be able to test this in a Command Prompt window. Go to Start, All Programs, Accessories, Command Prompt. When it opens, type sml at the prompt. That should put you into the interpreter where you can type in expressions. Remember that on Windows you terminate the session by typing Control-Z followed by hitting the Enter key. If this doesn't work for some reason, try saying set to see a complete list of your environment variables. You should see one for SMLNJ_HOME and the variable PATH should include c:\smlnj\bin.

To configure TextPad for color syntax highlighting:

  1. Download sml.syn to the Samples subfolder of your TextPad installation (on my computer it was "C:\Program Files\TextPad 4\Samples").

  2. In TextPad, select Configure, New Document Class with the following settings:
            Document class name: sml
            Class members:       *.sml
    
    When it prompts for syntax file name, select sml.syn and click on "Enable syntax highlighting".

  3. Test it by typing in some ML code like the following:
            val x = if 2 < 3 then 4 else 5;
    
    Save it to test.sml. When you go to save, be careful to have "Save as Type" set to "All files". TextPad has a habit of saving to Text files in which case it would save it as test.sml.txt. When you save it, you should see colors appear for the keywords.

Below are three optional configurations that you might want to do:

This final step is the most tricky but also probably the most useful. You can define a tool that will save the current file and load it in SML. Here are the basic steps to follow:
  1. Go to Configure, Preferences, Tools and select Add and then select Program.

  2. The program you want it to run is called sml.bat and you'll find it in the directory c:\smlnj\bin. Navigate to the file, select it, and then click on Apply.

  3. Expand the Tools menu (you'll probably see a "+" that you need to click on). Under that, select the sml command you just created. You need to change a few settings. Uncheck the box for "Capture output". Check the box for "Save all documents first". Leave everything else alone. Click on Apply and OK.

You should now find a selection under the Tools menu called sml. Try selecting it. It should launch the interpreter, load your file, and leave you at a prompt to interact with the interpreter. Remember to type Control-Z followed by the Enter key when you're done. It will take you back to TextPad.

For those of you using Windows, you'll find a great bonus. You can use the arrow keys inside of the ML interpreter. For example, if you want to get the expression you typed previously, just hit the up-arrow key. You can hit the up-arrow key several times in a row to get an even earlier expression. Also, If you're typing in a long expression and you notice a mistake towards the beginning, you can use the left-arrow key to position to the error and correct it, then use the right-arrow key to get back to the end of the expression. You can even use the Home and End keys to go to the beginning of the current line or the end of the current line.

If anyone has problems, post a message to the message board or email Stuart and we'll try to figure out what is going on.


Stuart Reges
Last modified: Thu Jan 4 12:27:31 PST 2007