Skip to main content

Importing Modules and Namespaces

This page is still under construction!

This feature is still not implemented!

Importing allows to use references outside the current script and scope. The Language offers different ways to import diferent references as needed for the user and in a way to allow the readability of the code.


Importing namespaces

simple imports can be done by writing:

from <namespace> import

Being <namespace> the relative or global reference to a namespace that is desired to import.

A example of simple import is:

from Std.Console import

Simple imports will allow the code to directly access members from the imported namespace inside it:

from Std.Console import

func main() !void {
# `writeln` is not a member of the `MyProgram` namespace,
# in reality it is being imported from `Std.Console`!
writeln("Hello, World!")
}

Specifiing Imports

Sometimes, is not necessary to import a entire namespace or doing so can cause a conflict with another member. Because of it, The language allows to specify what is being imported to the current scope with the syntax:

from <namespace> import { <ref...> }

Being <namespace> the parent of the desired imported content and <ref...> the references, separated by comma, of the desired members of the refered namespace.

Doing it also will not only import the desired content, as well scope the content of what is being imported inside a reference of the same name.

e. g.:

from Std import { Console, Mem }
# `Console` and `Mem` are now directly referenceable

func main() !void {
Console.writeln("Hello, World!")
}
from Std.Console import { write }
# only the `write` function is being imported

func main() !void {
write("Hello, World, ")
# Other references still need to be refered
# from the root!
Std.Console.writeln("I'm importing references!")

`writeln` is not defined in the current namespace, neither is being imported from `Std.Console!`
writeln("Oops")
}

Import with alias

To avoid reference conflicts or have control about the imported reference, is still possible to renemed it as desired using the keyword as as follows:

from Std.Console import { write, writeln as writeLine }

func main() !void {
write("Hello, World, ")
# Instead of refering as `writeln`, the function is
# refered as `writeLine`!
writeLine("I'm importing references!")

`writeln` is not defined in the current namespace, neither is being imported from `Std.Console` as `writeln`!
writeln("Oops")
}