Next Previous Up Top Contents Index

1 Using MLWorks interactively

1.6 Writing and reading source files

You may want to save the code you have so far typed into the listener to a file. You can do so by going to the menu bar, and choosing File > Save Listener Input As.... MLWorks pops up a file dialog with which you can choose a directory and a filename in which to save the source. Give the filename the suffix .sml to indicate that it contains Standard ML code; MLWorks will only treat files with the .sml suffix as source files. You can then edit the file as you would any other program, with a text editor.

If you have already used File > Save Listnener Input As... in this MLWorks session, you can now simply choose File > Save Listener Input instead, and MLWorks will update the file with any new source that you have entered since the last save.

Conversely, you may want to read ML code from a file in to your current context. There are various ways to do this; the simplest is to use the listener's File > Read Into Listener command. This produces a file dialog, and MLWorks will read code in from the file you choose as if it had been typed in to the listener window. The listener verifies all the declarations in the file, which must have a .sml suffix, in the usual way. In the example below, the file lists.sml was used; it contains definitions of a couple of simple list functions, length and flatten:

MLWorks> use "lists.sml";
val it : unit = ()
Use: lists.sml
val length : 'a list -> int = fn
val flatten : 'a list list -> 'a list = fn
MLWorks>

Note: The File > Read Into Listener command, in conjunction with the error-handling and editing facilities detailed in the next section, provides a handy way of interactively managing fairly small pieces of ML code. However, for larger or more complex sets of ML files, you should use the project compilation system, documented in Chapter 2. The other entries on the listener's File menu are related to the project system.

You can save the state of your entire MLWorks session to a file with the Podium's File > Save Session As... command. MLWorks will prompt you for a filename in which to save the image, which is just a normal MLWorks image file. To restart the MLWorks session from Windows, use the mlimage script. This script is installed by default in the bin subdirectory of your MLWorks installation.

mlimage <filename> [ <args> ]

See the UNIX manual pages for more on mlimage.


MLWorks User Guide version 2.0 for UNIX/Linux - 31 Jul 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker