Imports#
Import Statement#
The import
statement in jac, is used to include code from other Jac modules into the current program, allowing for code reuse and modular organization of the codebase. However, as jac is supersetting python, it allows importing of python modules as well as python libraries.
The functionality of this keyword remains same as in regular python but the syntax has been changed for better readability.
The :jac
annotation informs the jac compiler that it should be importing a jac module. The other main difference from regular python syntax is the use of from
keyword which is used before the module unlike in python and all entities imported from the module are placed within curly braces.
The above deiscription for importing python modules holds as long as the :py
annotation is used.
Include Statement#
Include statement in jac allows the programmer to separate their code into different modules and patch them into a single module.
In the above example, the global variables are defined in the 'global_vars.jac' module. As the 'main.jac' module includes the 'global_vars.jac' we can use the variables as if they were defined in 'main.jac'. Similar functionality for using import:jac
is shown in the 'main_import.jac' tab, where all required objects must be named in the import
statement which can be avoided by using include
instead.