Modules

Similarly to classes and functions, modules are another big packed chunk of code represented as a file. Every file that holds some Pa code is a module with its own namespace, accessing another module's function, variables, classes is done via importing.

Importing a module.

Importing a module is usually done at the top of a file, you can import a module using the keyword use followed by the path of the module file.


use "myModule.pc";
                    


In the previous example, the module is not imported to current module namespace, however the code inside it will still run.

Accessing from a module.

Accessing from a module is similar to how you access from a class, to use it in the current namespace you have to give it its own identifier.


use "myModule.pc" for myModule;

// calling hello() from myModule.
print myModule.hello();
                    


The standard library.

The standard library is a bunch of built-in handy modules in Pa that holds useful common operations, Importing a standard library is also done using the keyword use, followed by an identifier name of the module.


use Math;

// 1
print Math.abs(-1);
                    

The standard library documentation is planned and is in progress.

Private Values.

Private or local values to a module work mostly like classes' private attributes & methods explained in the previous chapter, it prevents the private values from being used by other modules incase of imports. This ability applies to any value in the module.


// private values in Module1.
private let x = 0;

private define add (a, b) {
    return a + b;
}

private class SomeClass {
    //...
}
                    


Now if we head to the second Module.


// Module2.

// import Module1.
use "Module1.pc" for module1;

module1.x; //error.
                    






You have done it! you have finished the basics of Pa. Congrats!!