Panther Search Documentation Tutorials Downloads Devlog Source Code

Modules

A module is a set of symbols that are sort of namespaced together. To import modules, you can use the @import intrinsic. This intrinsic takes just takes a single argument: a string of the path of the file or name of a named module. The special named modules are:

To import a file, you give the @import intrinsic the path of the file. If the path starts with a "./", the path will resolve relative to the current file, otherwise it will resolve relative to the current project.

For a symbol declared in the file to be accessible through the module of that file, it must be in global scope and have the #pub attribute, or be a member of a type declared in that file with has the #pub attribute.

Example

Panther
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// importing the standard library def std = @import("std"); // importing the math library def math = @import("math"); // because the math module is a sub-module of the std module, `math2` is equivalent to `math` def math2 = std.math; // just like with `math2`, `math3` is equivalent to `math` def math3 = @import("std").math; // importing a file def some_file = @import("some/path/some_file.pthr"); // importing a file with a relative def some_relative_path = @import("./relative/path/relative_file.pthr");