Modules

Using module

To use a module, we have a use statement.

use math

The above statement will load the math module. By default, this module return a map that contains its functions and properties.

puts math.abs(-20)    // 20

Like variable declaration, we can use multiple modules at one statement.

use math, io, task

Alias

Using module with another name, or many module have special name, alias is a great way to deal with them.

use m as 'math'
use my_math as 'this-is-my-custom-math'

Creating module

Createa new file: my_num.no

my_num.no
return 100

Use it in your code:

my_num.no returns a number, so my_num is a number, 100.

Of course, a function or any value works fine.

circle-info

A module can be used multiple times, but its code executes only once, on the first load.

circle-info

You should declare using of modules in top of your code.

Notes

The variable is declared in use statement is immutable, so you cannot modify it.

If a module is not found, you will get a runtime error.

Last updated