Packages

Introduction to packages in Sncode

Packages

NAME

packages - Introduction to packages in Sncode.

DESCRIPTION

A package is a container that may be used to group a set of related symbols (functions, constants, classes) together.

Create a package

Package declaration must begin with the keyword package, followed by its name, and must end with the keyword endp.

Package names can contain either letters [a-zA-Z], numbers [0-9] or _ but cannot begin with a number. It is recommended to avoid numbers and use the UpperCamelCase convention to name your packages.

For instance:

package Exemple
    e = "!";

    function hello()
        return "Hello ";
    endf

    function world()
        return " World";
    endf
endp

Use a package

In order to use a package that is in another file, you have to import it using the %include method:

%include "/path/to/your/package/exemple.sn";
Note: The file should be named the same as your package, but in lower case.

To call a function defined in a package, you have to use the operator :: between the package name and the function name:

a = Exemple::hello() .+ Exemple::world() .+ Exemple::e;

EXAMPLES

Calling a symbol (variable or function) from the same package :

package A
    function f1()
        return "f1";
    endf

    function f2()
        return A::f1() .+ ", f2";
    endf
endp

AUTHOR

Written by Jean-Georges Guenard, <jg@sednove.com>

Edit

© 2024 extenso Inc. All rights reserved.