File path resolution

A file path specified in a command line argument and in a 'use' directive is resolved relative to the current base directory and the effective load path list.

The base directory

The base directory of a file path in a command line argument or in a 'use' directive at the interpreter prompt is the current working directory. The base directory of a file path in a 'use' directive appearing in a some file is the directory of that file.

The SML# system also maintains the load path list, which is an ordered list consisting of the following directories.

(1) The directories specified by a command line option -I.

\$ smlsharp -I /foo -I /bar -I /boo

(2) The directories listed in an environment variable SMLSHARP_LIB_PATH

(Unix)    SMLSHARP_LIB_PATH=/foo:/bar:/boo
(Windows) SMLSHARP_LIB_PATH=\foo;\bar;\boo

(3) The SML# install directory

(4) The current directory

In the resolution, the compiler examines them from (1) to (4).

The path resolution rule.

(1) If the path is an absolute path starting with the root directory, it is used as is. The followings are absolute paths.

/foo/bar
D:/foo/bar

(2) A path that begins with "." or ".." is interpreted relative to the base directory. For example, if the current base directory is /doo/bee, the following paths

./foo/bar
../foo/bar

are resolved to /doo/bee/foo/bar and /doo/foo/bar, respectively.

(3) Otherwise, the path is resolved using the effective load path list. For example, if the current effective load path list is

{/bro/sis, /mom/pap, .}

then

foo/bar

denotes one of the paths

{/bro/sys/foo/bar, /mom/pap/foo/bar, /doo/bee/foo/bar}.

The SML# runtime system examines this list from left to right until an existing file is found.