
2 Building Applications
zval.sml is in a subdirectory values of the start-up directory. How does MLWorks find zval.sml? The answer is that MLWorks keeps a notion of the source path, a list of directories which it should search, in order, for files and subdirectories. The source path can be modified with the Paths > Source Path menu item on the MLWorks podium.
Note: The source path does not work in quite the same way as the UNIX and Windows PATH environment variables. It is not used as a means of locating files that are not given with full pathnames; rather, it is used as a means of determining where source-compound hierarchies start. An explanation follows.
Each element of a source path is a directory name, such as /u/sml. Some path mechanisms would use this directory name as a place to look for a filename that was given to it without a full, disambiguating path prefix, for example as prog.sml rather than as /u/sml/prog.sml.
The MLWorks source path is instead used to declare directories in which compound hierarchies can begin. Thus /u/sml to the MLWorks source path means that in /u/sml there may be units of code, and also subdirectories that should be considered compounds. This interpretation allows MLWorks to conclude that, with a path of /u/sml, a file it looks at called /u/sml/values/zval.sml should be considered a unit zval in a compound values. And crucially, the source path assures MLWorks that the file is not to be considered a unit zval in a compound values that is a subcompound of a compound sml that is itself a subcompound of a compound u, or indeed any of the other interpretations possible without this notion of where the compound hierarchy begins.
Paths > Source Path shows a list of the directories on the current path, and allows you to edit it by adding and removing items. By default, the initial source path on starting MLWorks contains only the start-up directory. However, the source path may be changed by adding an entry in the path dialog or by using the function
Shell.Path.setSourcePathThis function takes an argument of type
string list; each string should be an absolute pathname, or a relative pathname to be interpreted relative to MLWorks' "current directory" (initially the directory from which it is started up). If you want a particular source path set on start-up, you could put a call to this function in the MLWorks start-up file (see Section 1.13, "The MLWorks start-up file"). Alternatively you can set the desired source path in the MLWORKS_SRC_PATH environment variable before invoking MLWorks.
All require declarations are interpreted relative to the current compound. In the example of Section 2.3, xval is in the top-level compound, so MLWorks searches the source path for a directory values containing a file zval.sml. If this require appeared in a unit maths.xval, MLWorks would look for the unit maths.values.zval.
The ^ character can be used to specify the parent compound: if the dependency between xval and values.zval were the other way round, zval.sml might be changed to read

Figure 2.9 Require statement for unit zval if it were dependent on xval.
A unit imported with require is searched for along the entire source path, so in this example MLWorks would search the entire path for xval.sml; it would not look only in the directory immediately above values.
The $ character denotes a notional root compound. If a unit A.B.C.foo contained the line
require "$.bar";it would denote the unit
bar, not the unit A.B.C.bar.

Generated with Harlequin WebMaker