PACKAGE 1g 2023-09-12 laplante@plcb.ca GOWEB


title: “Package” author: “Pierre Laplante laplante@plcb.ca” date: “2023-09-12” version: “1.0.0” section: “1g”

category: “GOWEB”

Description

A package is used to group related functions and variables under a common namespace.

Functions inside a package can be called using the syntax:

package_name::function_name();

Variables can also be defined within a package and accessed using the same notation:

package p {
    x := 5;

    func f() {
        "x="; p::x;
    }
}

p::f();
p::x;

Examples

Invalid Package Usage

res={{
    package allo {
        package error {
        }
    }
}}.

Output:

.*Parser error, can't use a package error in package allo.

Package Function Example

res={{
    package p {
        func f(i) {
            "i="; i;
        }
    }

    p::f(5);
}}.

Output:

res=i=5.

Package with Function Overriding

res={{
    package p {
        func f(i) {
            "i="; i;
            f(i*2);
        }
    }

    func f(i) {
        "i2="; i;
    }

    p::f(5);
    f(6);
}}.

Output:

res=i=5i2=10i2=6.

Author

See also

Version