Sn Tin

Reference

Package docs

API documentation generated by tin doc from a package's source and its /// comments. Below: the example package examples/packages/geometry.

tin doc

A /// comment documents the declaration under it: a function, tool, type, field, trait, trait method, agent or constant. A file's first // comment block introduces the file. tin doc lists every public declaration with its signature as the compiler reads it, with methods under their type. Names starting with __ are left out.

/// A 2D vector, in meters.
type Vec = {
  /// Across, positive to the right.
  x: float,
  y: float,
}

/// The length of `v`: `Vec { x: 3.0, y: 4.0 }.len()` is 5.0.
fn Vec.len(v: Vec): float => sqrt(v.x * v.x + v.y * v.y)
$ cd examples/packages/geometry && tin doc
doc/index.html  2 files, 5 items

In a folder with a tin.toml, tin doc documents every .tin file next to it and in src/, except main.tin. Name files to document only those. It writes one page per file and an index.html into doc/ (-o for another folder), each a single HTML file with no scripts. --json prints the same content as data. Comments may use `code`, **bold**, [links](https://…), paragraphs and - lists. The editor's hover shows the same comments (see tin lsp).

examples/packages/geometry/lib.tin

geometry: small 2D helpers for robot arms. Import it with import "geometry", or one file with import "geometry/vec".

const VERSION

let VERSION = "0.1.0"

fn toRadians

fn toRadians(deg: float): float

Degrees to radians: toRadians(180.0) is π.

examples/packages/geometry/vec.tin

Vectors in the plane.

type Vec

type Vec = { x: float, y: float }

A 2D vector, in meters.

field x

x: float

Across, positive to the right.

field y

y: float

Up, positive away from the floor.

method len

fn Vec.len(v: Vec): float

The length of v: Vec { x: 3.0, y: 4.0 }.len() is 5.0.

method plus

fn Vec.plus(v: Vec, w: Vec): Vec

v and w added component by component.

type Reach

type Reach = Inside | Edge | Outside(float)

How a point relates to an arm's reach.

variant Inside

Inside

variant Edge

Edge

variant Outside

Outside(float)

fn reach

fn reach(p: Vec, limit: float): Reach

Where p is for an arm that reaches limit meters. Edge means within 1 cm.