Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Packages

Modules that sit beside one program are enough for that program. Modules meant for several programs become a package: a directory tree of modules with a tiko.toml at its root naming the package. A program that uses the package says where to find it, in a tiko.toml of its own.

units/
    tiko.toml
    length/length.tiko
    temperature/temperature.tiko
app/
    tiko.toml
    main.tiko
# A package: a directory tree of modules with a tiko.toml at its root.
[package]
name = "units"
#module "length"

public const FEET_PER_METRE = 3.28084

public function ToFeet( byval metres as float64 ) as float64
    return metres * FEET_PER_METRE
end function
#module "temperature"

public function ToFahrenheit( byval celsius as float64 ) as float64
    return celsius * 9 / 5 + 32
end function

The program's tiko.toml names the dependency by path, and declares the program it builds:

# The program's project: its name, what it depends on, what it builds.
[package]
name = "app"

[dependencies]
units = { path = "../units" }

[target.convert]
main = "main.tiko"
'' A path that starts with a dependency's name is found through
'' tiko.toml, wherever that package lives.
#import "units/length"
#import "units/temperature"
#import "std/strings"

print strings.Format( "100 m is {:.1f} ft", length.ToFeet( 100 ) )
print strings.Format( "25 C is {} F", temperature.ToFahrenheit( 25 ) )

Built with tiko build in the app directory, and run as out/debug/convert:

Output

100 m is 328.1 ft
25 C is 77 F
  • [package] name is the package's name. The module length inside units has the full name units.length, so it never collides with a length module from another package. The program still calls it length, the last part of the import path.
  • [dependencies] maps a package name to a directory, relative to the tiko.toml. An import whose first part is units is looked for there. The dependency is written in the repository, so a fresh checkout builds with no setup.
  • [target.convert] declares an executable built from main.tiko. The Building section covers targets, profiles and tiko build.

tiko --print-graph main.tiko lists the modules a program imports, in the order they are built, with the directory each came from. For this program it prints the standard library's modules and then:

units.length       ../units/length
units.temperature  ../units/temperature

Activities

  1. Add a module units/weight with a public ToPounds and use it from the program.
  2. Rename the dependency in app/tiko.toml to measures without changing the imports, and read what the build says.