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] nameis the package's name. The modulelengthinsideunitshas the full nameunits.length, so it never collides with alengthmodule from another package. The program still calls itlength, the last part of the import path.[dependencies]maps a package name to a directory, relative to thetiko.toml. An import whose first part isunitsis looked for there. The dependency is written in the repository, so a fresh checkout builds with no setup.[target.convert]declares an executable built frommain.tiko. The Building section covers targets, profiles andtiko 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
- Add a module
units/weightwith a publicToPoundsand use it from the program. - Rename the dependency in
app/tiko.tomltomeasureswithout changing the imports, and read what the build says.