Skip to content
English

Modules

A module is a collection of functions and values with a name. Some modules are built into Algorizm; others are files that you write yourself.

Using a module

import makes a module available. Its contents are then reached through the module's name and a dot.

import matematika

chiqar(matematika.ildiz(144), yaxlitla(matematika.PI, 4))
chiqar(matematika.daraja(2, 10), matematika.pastga(3.7), matematika.yuqoriga(3.2))
Output
12.0 3.1416
1024.0 3 4

import is usually written at the beginning of a file. Importing the same module more than once does no harm.

The standard library

These modules come with Algorizm. Each is described on the page Standard library.

Module What it is for
matematika square root, powers, trigonometry, logarithms, PI and E
tasodif random numbers, random choice, shuffling
vaqt the current time, waiting
sana dates: taking apart, building, formatting, names of weekdays and months
fayl reading, writing, copying and deleting files
papka folders and paths
tizim command-line arguments, environment variables, stopping the program
json reading and writing JSON
qolip regular expressions

Your own modules

Any .alg file can be a module. import nom looks for nom.alg in the folder of the file that imports it, runs it once, and makes its top-level names available as nom.x.

Suppose the file geometriya.alg contains:

PI = 3.14159

funksiya doira_yuzasi(r):
    qaytar PI * r * r

funksiya tortburchak_yuzasi(eni, boyi):
    qaytar eni * boyi

Then another file in the same folder can use it:

import geometriya

chiqar(geometriya.doira_yuzasi(2))
chiqar(geometriya.tortburchak_yuzasi(3, 4), geometriya.PI)
Output
12.56636
12 3.14159
  • The module's file is run only once, however many files import it.
  • Everything defined at the top level of the module, functions, classes and variables, can be reached from outside.
  • The name of the file must be a valid name: letters, digits and _.

Names after a dot

After a dot, keywords are ordinary names. That is why papka.ota(...) works although ota is a keyword, and why a field or method may be called har or ber.

Next

The tutorial ends here. The reference starts with Keywords and operators, and the examples show complete programs.