Hymn Script
Home Learn Play Download Source Light

Imports


Imports

Imports are used to execute additional hymn files.

# my-file.hm
set HELLO = "Hello "
func world() {
  return "world!"
}
echo "I was imported!"
>>> echo PATHS
["<parent>/<path>.hm", "./<path>.hm", "./libs/<path>.hm"]
>>> echo IMPORTS
{}
>>> use "my-file"
I was imported!
>>> echo IMPORTS
{ "/absolute/path/to/my-file.hm": true }
>>> echo HELLO + world()
Hello world!

External scripts are executed immediately when a `use` statement is called.

There are no separate namespaces. All global variables defined in an external script are accessible in the same global scope.

The global `PATHS` variable controls where script files are searched for. It can be modified at runtime to change script loading behaviour.

Scripts are saved to the global `IMPORTS` variable. Scripts present in `IMPORTS` will not be executed again. However, `IMPORTS` can be modified and entries removed such that a script can be imported twice.


Back to Exceptions Back to Table of Contents