Modules
A module groups declarations. Each file is a module, and mod declares one inside another:
mod shop = { pub def tax_rate = 0.25 pub def with_tax(price! num)! num = price * (1 + tax_rate) def margin = 0.4}shop:: reaches the names in shop:
shop::with_tax(8) // {10}Only pub declarations are visible outside a module:
shop::margin // error SK4202The standard library
Section titled “The standard library”SakaQL comes with standard library modules, such as str for text and num for numbers:
str::upper_ascii("saka") // {"SAKA"}The prelude’s names, such as sum and count, need no prefix.
Module files
Section titled “Module files”The REPL starts in main.saka, the database’s main file. The REPL’s commands start with a colon. :create makes a new file and switches the REPL to it:
:create "pricing.saka"The declarations you enter now go into pricing.saka:
pub def discount(price! num)! num = price * 0.9:module switches back to main.saka, where use mod imports the new module:
:module "main.saka"use mod pricing = "pricing.saka"pricing::discount(10) // {9}The Files sidebar lists the database’s files.