Conversions API
Functions for inspecting and converting between types.
typeof(value)
typeof(value)
Returns a string describing the type of value.
value(any) — the value to inspect
Returns: string — one of the type names listed below.
| Value | Returns |
|---|---|
null | "null" |
| Booleans | "bool" |
| Numbers (integer & float) | "number" |
| Strings | "string" |
| Lists | "list" |
| Maps | "map" |
| Struct instances | "struct" |
| Struct schemas | "struct_schema" |
| Enum values | "enum" |
| Enum schemas | "enum_schema" |
| Functions & closures | "function" |
| Prompt tags | "prompt_tag" |
| Continuations | "continuation" |
typeof(42) // "number" typeof("hello") // "string" typeof(true) // "bool" typeof(null) // "null" typeof([1, 2, 3]) // "list" typeof({"a": 1}) // "map"
num(value)
num(value)
Converts a string to a number. Leading and trailing whitespace is trimmed before parsing.
value(string) — the string to parse
Returns: number
Errors: if value is not a string, is empty, or is not a valid number format.
num("42") // 42 num("3.14") // 3.14 num(" -7 ") // -7 num("1e10") // 10000000000
str(value)
str(value)
Converts any value to its string representation.
str(42) // "42" str(3.14) // "3.14" str(true) // "true" str(null) // "null" str([1, 2, 3]) // "[1, 2, 3]"
str(format, ...)
str(format, ...)
Formats a string using a format template and arguments. Supports up to 25 arguments after the format string.
| Specifier | Type | Description |
|---|---|---|
%s | string | Insert a string value |
%n | number | Insert a number |
%b | boolean | Insert true or false |
%v | any | Insert any value’s string representation |
%% | — | Literal % character |
str("Hello, %s!", "world") // "Hello, world!" str("%s is %n years old", "Alice", 30) // "Alice is 30 years old" str("Result: %b", true) // "Result: true" str("Value: %v", [1, 2]) // "Value: [1, 2]" str("100%%") // "100%"
See also: String API — Math API