Installing SML on Windows

This document describes the basic steps for installing SML on a Windows machine for use with TextPad.

To configure TextPad for color syntax highlighting:
  1. Download sml.syn to the Samples subfolder of your TextPad installation (on my Windows XP computer it was "C:\Program Files\TextPad 5\Samples" and on my 64-bit machine it was "C:\Program Files (x86)\TextPad 5\Samples." Note: on my Windows Vista machine, the folder was set to "read only", so I saved the file to the desktop, dragged it to the correct folder, and told the computer that it was okay to apply administrator privileges.

  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:\Program Files\SMLNJ\bin (it was c:\Program Files (x86)\SMLNJ\bin on my 64-bit machine). 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/External 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.

There is still a problem to deal with. When you load a legal sml file, the command above works fine. But when you try to load a file that has some kind of syntax error, you'll find that the window quickly collapses before you can see the error. I recommend the following. Repeat the steps above to create a second command. Do everything the same except leave the "Capture output" box checked (you want to capture output when there is an error). You should use this version when you have an error message that you want to see. The output will be displayed in the "Tool Output" window. When you go to Preferences/Tools and see your list of tools, you'll now see "sml" listed twice. Click on the second one and you'll have the option to rename it something like "sml error".

(Another simple way to make it possible to see your ML errors is to open up the C:\Program Files\SMLNJ\bin\sml.bat file in your text editor and add a new line at the bottom of it containing simply the word:

        pause

This should cause the sml.bat to display a "Press any key to continue..." message before exiting.)

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.

In the attu instructions you will see a description of some environment variables that you might want to set. If you have set up the SML tool, you can go to Configure, Preferences, Tools, Sml. You should see this option:

        Parameters: $File
Change this to the following to get the suggested settings for the environment variables:

        Parameters: -Cprint.depth=20 -Cprint.length=1000 $File
If anyone has problems, post a message to the message board or email the instructor and we'll try to figure out what is going on.