Skip to main content

Module System

Lesma's module system is still a work in progress. Similar to Python's system, you can import whole files, or select functions and object from another file.

A module is a file containing Python definitions and statements. The filename is the module name with the suffix .les appended

There are a few differences in Lesma's module system compared to other implementations in languages like Python.

Imports & Exports

The syntax and semantics are exemplified below.

# tests/lesma/function_call.les
export def fib() -> int
return 101

export class Animal
var x: int

def new()
self.x = 101

def getX() -> int
return self.x
# main.les

# Import from standard library
import time


# Import file
import "tests/lesma/function_call.les"

# Module is then given an alias based on filename

let x = function_call.Animal()

# Import time in scope
from time import sleep


let x = Animal()

# Import sleep function with alias
from time import sleep as my_sleep


# Import all functions from module
from time import *

# Import all functions from module with alias
import time as my_time


Top-Level Statements

Top-level statements are not executed once imported. This is in contrast to Python where it's executed exactly once. Because of this it's not recommended to initialize parts of your module outside of classes and functions.