Using ML at Graceland

for CPSC3400

General

ML is a language you will use in this course, and we have installed SML (Standard ML of New Jersey) on the CSLab workstations for you to use (at present it has not been installed on trinity). You can download and install it yourself on your own PC.

For convenience, you can get the copy that I made available locally at http://csit.graceland.edu/cs/downloads/.

However, you may want to go directly to the SML/NJ site to get the latest version, http://www.smlnj.org/.

Go to Start-->Programs-->Development-->StandardML on any of the CSLab workstations (booted for Windows). There you will find links for the documentation and the Standard ML interpreter.

Launching SML

There are different ways to launch the SML interpreter. Use the one that is the least confusing or works best for you:

  1. Go to Start-->Programs-->Development-->StandardML and select the Standard ML interpreter. This will probably be different on your PC (in the CSLab we consolidated various interpreters under Development).

  2. Go to C:/Program Files/ML/bin/ and run the batch file sml.bat (location may be different on your installation). Method #1 above is actually just a shortcut for running this batch file.

  3. If the PATH variable has been set up for the ML bin directory, then you can run sml from any DOS prompt screen. The CSLab workstations have had this setup in the past, but not necessarily now. You may or may not want to do this on your own installation.

  4. Create a shortcut to the sml.bat file (see #2 above) and move it to the folder where you will be doing your SML work (somewhere on your H-drive to avoid loss). Right-click the shortcut to set useful screen properties, such as Layout (increase buffer height for scrollback and window height to see more).

  5. Create a copy to the sml.bat file (see #2 above) and move it to the folder where you will be doing your SML work (somewhere on your H-drive to avoid loss). Then make a shortcut to your copy of the batch file (in the same folder if you like) so that you can right-click the shortcut and set useful screen properties for it (similar to #4 above).

Items #1, #2, and #3, are probably most useful for running the interpreter so that you can interact directly with it, trying out SML statements to see what they do (you should do this while reading the textbook chapters on ML).

Items #4 and #5 will be more convenient for running SML files, that is, a text file filled with a sequence of SML statements that you want to have the interpreter load and run. See next section.

Running SML Program Files

You can create your SML programs as text documents using a simple text editor, such as WordPad. Make sure to save these files with the .sml extension. An SML file contains a series of SML statements, each ended with a semicolon. You cannot use a variable before it is declared. Here are the various ways to run an SML file named foo.sml that is in a file on your H-drive in H:\cpsc3400\my_ML_stuff:

  1. Enter 'use' command with full pathname -- If you used #1, #2, or #3 above to launch the interpreter, you can enter the use command and load the file by giving its full-pathname. Since the backslash is an escape character in SML strings, you must use "\\" to stand for a single backslash. Here is how you would load and run foo.sml:
           use "H:\\cpsc3400\\my_ML_stuff\\foo.sml";
  2. Enter 'use' command with simple filename -- If you used #4 or #5 above to launch the interpreter, then you are running [sml.bat] from the same directory as foo.sml. Therefore, you need not give a complicated path to the file:
           use "foo.sml";
  3. Drag-and-drop -- If you have an icon showing for the SML interpreter (whether it be the original sml.bat, a copy of it, or a shortcut to either) you can drag-and-drop the file icon onto the interpreter icon to run it. In this case, they need not be in the same folder. Thus, in our example you can drag the foo.sml icon onto the icon for the SML interpreter. You will get whatever screen characteristics are setup for the icon you drug it to.

  4. Enter 'use' command with simple filename [second way] -- Finally, you could open a DOS command prompt screen, enter cd commands to navigate to the directory containing foo.sml, and enter sml (assuming that PATH has been set up for this to work, as in #2). In this case, you can enter the same simple use command as shown in B above.