Packages & Imports

Packages and Imports

Fahrenheit allows you to organize your code into packages and import them into other scripts.

Defining Packages

To define a package, use the package keyword followed by the package name and a block containing the definitions.


package net.alantea.utils {
    function log(msg) {
        print("[LOG] " + msg);
    }
    
    structure Config {
        host;
        port;
    }
}
    

Nested Packages

Packages can be nested inside other packages.


package net {
    package alantea {
        package utils {
            function log(msg) { print(msg); }
        }
    }
}
    

Importing Files

You can import other Fahrenheit files using the import statement.

Import with Alias

Imports the file and namespaces its content under the alias.


import "utils.fh" as Utils;
Utils.log("Hello");
    

Import without Alias

Executes the imported file in the current scope. This is useful for loading libraries that define packages or set up global state.


import "utils.fh";
net.alantea.utils.log("Hello");