Jarog supports imports. Each program can be imported as a unit. If program is designed to be a unit it can contain no definition named main. In this case program can not be executed and can be only imported as a unit.

Units should be placed in the same folder as a main program or in sub-folder. Also there is a special place, configured in Jarog Machine. Units stored there are accessible for all programs.

Units can be imported with load instruction. Also there should be specified a namespace to access definitions in loaded unit.

Load instruction looks next:

load "<relative path to unit name without suffix>" as <namespace>;


load "script" as s1;
load "../script" as s2;
load "folder/script" as s3;

Lets assume we have file unit.jr with next content in the same folder as our main program:

type myInt: int;
const a := "hello";

Now lets import this unit into our program:

load "unit" as unit;

After that we can access definitions from unit.jr in next way:

const b := unit::a + " world";
var i: unit::myInt := 3;

Unit unit.jr also can has it’s own imports, but only things directly defined in unit can be imported from it. I.e. you can not use unit1::unit2::smth.

Also notice that all variables imported from unit are read-only and can not be changed, but still can be altered if some function that can change it is imported unit and invoked.

Main function

Each unit must have function named main unless it is a library unit. Function main should accept one parameter - a list of strings. Each time unit is called from command line, command line arguments are passed to this list. If unit has no main function it cannot be ran from command line.

Built-in units

Jarog has some built-in units, that can be loaded and used. Built-In units have names enclosed with <>. <io> for example. See the list of built-in units, functions and constants in additions.

load "<io>" as io;

See appendix for all built-in units.