MillScript Loader

The loader reads the MillScript file contents and passes it to the MillScript compiler. Any MillScript is valid in the MillScript file.

There is only one restriction on the MillScript code that you put in the MillScript file. A variable with the same name as the MillScript file must be declared by the end of the file. e.g. if you've created a file called sample.ms, with the following contents:

import SomePackage;   # For example only
var this = "that";
      

When you try to autoload the file, MillScript will stop and complain that it can't find a definition for the variable sample, e.g. you would get something similar to:

:-) sample;
AUTOLOADING sample

MISHAP  : Could not find the definition for this variable
NAME : sample
PHASE   : Compile
Trapped : org.millscript.millscript.Alert$EscapeException
Resetting input and resuming execution
      

If we were to add the following line to the end of the file:

const sample = this ++ " string";
      

When we try to autoload the file again, we would see the following:

:-) sample;
AUTOLOADING sample
There is 1 result
"that string"
      

File Format

The format of a MillScript file is any valid MillScript statement, which declares a variable with the same name as the MillScript file. e.g. if you create a file called nfib.ms, with the following contents:

function nfib( n ) =>
  if n <= 1 then
    1
  else
    1 + nfib( n - 1 ) + nfib( n - 2 )
  endif
endfunction;
        

The above statement defines a function and assigns it to the variable nfib.

Use

  1. Create an ms file in your inventory, containing the required MillScript statement.
    function nfib( n ) =>
      if n <= 1 then
        1
      else
        1 + nfib( n - 1 ) + nfib( n - 2 )
      endif
    endfunction;
                
  2. We could use this MillScript file as in the following interpreter session:
    :-) nfib( 10 );
    There is 1 result
    177
                

Notes