Reference · Standard library
- The language
- Agents and tools
- Model providers
- The Anthropic API
- Talking agents
- Standard library
- Glossary
- Package docs
- Telemetry
- Robots
- Servers
- Deploying
- tin.ad
- The tin command
- How it works
On this page
Standard library
Every function and type available without an import, generated from the library source.
Nothing here needs an import. The library is written in Tin and compiled together with your
program; only the functions you use end up in the .wasm file. The 213 signatures
below are read from the library source when this page is built.
Any function can be called as a method on its first argument: xs.map(f) is
map(xs, f), and text.trim() is string.trim(text). A name like
string.slice or Array.slice says which type the method belongs to, which is
how two types can share a method name.
Built in
These are part of the compiler, because they work on every type or have no ordinary signature.
print(value)Writes any value, then a line break. print() writes an empty line.
write(value)Writes any value without a line break.
str(value): stringAny value as text, the same text print and "{value}" produce.
int(x): intA float truncated toward zero (a panic if it is NaN or does not fit), an i64 that fits, a char's code point, or a bool as 0 or 1.
float(x): floatAn int as a float.
exit(code: int)Stops the program with this exit status. Like panic it never returns, and a tool or task cannot catch it. Code an agent writes cannot call it.
panic(message: string)Stops the program with a message. Inside a tool, the message goes back to the model as a failed call.
xs.len, text.lenThe number of items in an array, or bytes in a string. A field, not a call.
xs.push(item)Adds an item to the end of an array. Needs a var.
xs.pop()Removes and returns the last item. Panics on an empty array. Needs a var.
task.stop()Stops a task and every task it started. They end at their next pause.
task.done(), task.stopped()Whether a task has finished or been stopped, and whether it was stopped.
PI3.141592653589793
var xs = [3, 1, 2]
xs.push(9)
print("{xs.len} items, last was {xs.pop()}")
print(str(1.5) + " " + str(true) + " " + str([Some(1), None]))
print(int(2.9) + int(true)) 4 items, last was 9
1.5 true [Some(1), None]
3 Option and Result types
type Option<T> = Some(T) | NoneA value that may be missing. Tin has no null.
type Result<T, E> = Ok(T) | Err(E)The outcome of something that can fail. Tin has no exceptions.
type AgentError = TurnLimit(int) | OverBudget(int) | Refused(string) | Cut | NoAnswer | Failed(string)Why an agent call gave no answer, from A.try(prompt).
Modules
Each module has its own page: every symbol with its signature, a summary, a link of its own, an example that runs when the page is built, and where to read more.
Strings and characters
Strings are immutable UTF-8. Positions and len count bytes, so a character outside ASCII takes more than one. A char is one Unicode code point.
string.byteAtstring.slicestring.charAtstring.charsfromCharschar.isDigitchar.isLetterchar.isSpacechar.isUpperchar.isLowerchar.upperchar.lowerchar.comparestring.indexOfstring.containsstring.startsWithstring.endsWithstring.isEmptystring.splitstring.trimstring.upperstring.lowerstring.repeatstring.replacestring.padLeftstring.padRightjoinparseIntparseFloat
Arrays
These return new arrays and leave the original as it was, so xs.sort() on a line of its own is a compile error (it would do nothing): keep the result, xs = xs.sort(). The same holds for trim, upper, replace and the other string methods. push and pop (built in) change a var in place.
Map and Set
A Map<K, V> looks values up by key; a Set<T> holds each value once. Both are values: assigning one copies it.
Option and Result
There is no null and there are no exceptions. A value that may be missing is an Option; a call that can fail returns a Result, and ? passes a failure up.
Numbers and math
int is 32-bit and checked: overflow is a panic, not a wrap. The Bits module has wrapping arithmetic.
Bits
Rotations and wrapping arithmetic for checksums and hashes, where overflow is meant to wrap.
Bytes
Binary data: raw bytes, with hex and base64 in both directions. text() checks that the bytes are UTF-8.
Json
Read and write JSON whose shape is not known in advance. For a shape you know, a typed agent reply or a struct is better.
Hashing
SHA-256 and HMAC-SHA-256, written in Tin. The Bedrock provider signs its requests with them.
Time and I/O
Clocks, waiting, input, the environment and HTTP. Each of these reaches outside the program, so tin caps reports it.
Traits
The traits the library uses as bounds, such as T: Ord on sort and max. Implement one for your own type to use those functions with it.
Voice
The types a voice agent session uses: its events, audio in and audio out. See the status page for what has been verified with real providers.