99 std/
1010 core.top
1111 string.top
12+ math.top
1213 collections/
1314 list.top
15+ aliases.top
16+ functional.top
1417```
1518
1619### std.core
@@ -37,7 +40,35 @@ Utilities layered on top of the VM's native list support (`VList`, `IListGet`, `
3740| ` list_concat ` | Delegates to the runtime concatenation primitive. |
3841| ` list_single ` | Creates a one-element list. |
3942
40- At this stage higher-order helpers (` map ` , ` filter ` , …) are earmarked for a future iteration once the parser grows richer list syntax.
43+ ### std.collections.aliases
44+
45+ Convenient short aliases for common list operations:
46+
47+ | Symbol | Description |
48+ | --------| -------------|
49+ | ` length(lst) ` | Alias for ` __list_length ` . Returns the number of elements in a list. |
50+ | ` head(lst) ` | Alias for safe first element access. Returns ` nil ` if list is empty. |
51+ | ` tail(lst) ` | Returns all elements except the first. Returns ` [] ` if list is empty or has one element. |
52+ | ` concat(left, right) ` | Alias for ` __list_append ` . Concatenates two lists. |
53+ | ` last(lst) ` | Alias for safe last element access. Returns ` nil ` if list is empty. |
54+
55+ ### std.collections.functional
56+
57+ Higher-order list functions for functional programming:
58+
59+ | Symbol | Description |
60+ | --------| -------------|
61+ | ` fold(lst, init, func) ` | Reduces a list to a single value using an accumulator function. Left fold. |
62+ | ` map(lst, func) ` | Transforms each element of a list using the provided function. |
63+ | ` filter(lst, predicate) ` | Returns a new list containing only elements that satisfy the predicate. |
64+ | ` reverse(lst) ` | Returns a new list with elements in reverse order. |
65+ | ` take(lst, n) ` | Returns the first ` n ` elements of the list. |
66+ | ` drop(lst, n) ` | Returns all elements after dropping the first ` n ` . |
67+ | ` find(lst, predicate) ` | Returns the first element matching the predicate, or ` nil ` if none found. |
68+ | ` contains(lst, value) ` | Returns ` true ` if the list contains the value, ` false ` otherwise. |
69+ | ` index_of(lst, value) ` | Returns the index of the first occurrence of value, or ` -1 ` if not found. |
70+ | ` range(start, end) ` | Generates a list of integers from ` start ` to ` end ` (inclusive). |
71+ | ` zip(lst1, lst2) ` | Zips two lists into a list of pairs up to the shorter length. |
4172
4273### std.string
4374
@@ -48,6 +79,74 @@ Convenience wrappers around the existing string builtins:
4879| ` string_is_empty ` | Checks whether a string has length zero. |
4980| ` string_starts_with ` / ` string_ends_with ` | Prefix and suffix checks expressed via ` __substring ` . |
5081
82+ ## Built-in Functions
83+
84+ The Topineur runtime provides several built-in functions implemented in Haskell:
85+
86+ ### Math Functions
87+
88+ | Function | Signature | Description |
89+ | ----------| -----------| -------------|
90+ | ` abs(x) ` | ` Int\|Float -> Int\|Float ` | Returns the absolute value. Preserves input type. |
91+ | ` sqrt(x) ` | ` Int\|Float -> Float ` | Returns the square root. Always returns Float. |
92+ | ` pow(a, b) ` | ` Int\|Float, Int\|Float -> Float ` | Exponentiation. Returns Float. |
93+ | ` floor(x) ` | ` Int\|Float -> Int ` | Largest integer not greater than ` x ` . For Int, passthrough. |
94+ | ` ceil(x) ` | ` Int\|Float -> Int ` | Smallest integer not less than ` x ` . For Int, passthrough. |
95+ | ` round(x) ` | ` Int\|Float -> Int ` | Rounds to the nearest integer (banker's rounding as in Haskell). For Int, passthrough. |
96+ | ` sin(x) ` | ` Int\|Float -> Float ` | Sine of ` x ` in radians. |
97+ | ` cos(x) ` | ` Int\|Float -> Float ` | Cosine of ` x ` in radians. |
98+ | ` tan(x) ` | ` Int\|Float -> Float ` | Tangent of ` x ` in radians. |
99+ | ` asin(x) ` | ` Int\|Float -> Float ` | Arc-sine in radians. Domain [ -1,1] . |
100+ | ` acos(x) ` | ` Int\|Float -> Float ` | Arc-cosine in radians. Domain [ -1,1] . |
101+ | ` atan(x) ` | ` Int\|Float -> Float ` | Arc-tangent in radians. |
102+ | ` atan2(y, x) ` | ` Int\|Float, Int\|Float -> Float ` | Arc-tangent of ` y/x ` accounting for quadrant, in radians. |
103+ | ` pi ` | ` Float ` | π constant (3.14159…). |
104+ | ` e ` | ` Float ` | Euler's number e (2.71828…). |
105+
106+ ### std.math (Topineur)
107+
108+ Convenience numeric utilities implemented in Topineur:
109+
110+ | Function | Signature | Description |
111+ | ----------| -----------| -------------|
112+ | ` min(a, b) ` | ` Int\|Float -> Int\|Float ` | Returns the smaller of two numbers. |
113+ | ` max(a, b) ` | ` Int\|Float -> Int\|Float ` | Returns the larger of two numbers. |
114+ | ` clamp(x, lo, hi) ` | ` Int\|Float -> Int\|Float ` | Clamps ` x ` into ` [lo, hi] ` using ` max(lo, min(x, hi)) ` . |
115+ | ` sign(x) ` | ` Int\|Float -> Int ` | Returns ` -1 ` , ` 0 ` , or ` 1 ` . |
116+
117+ ### Type Conversions
118+
119+ | Function | Signature | Description |
120+ | ----------| -----------| -------------|
121+ | ` int(x) ` | ` Int\|Float\|String -> Int ` | Converts to Int. Truncates floats towards zero. |
122+ | ` float(x) ` | ` Int\|Float\|String -> Float ` | Converts to Float. |
123+ | ` show(x) ` | ` Any -> String ` | Converts any value to its string representation. |
124+
125+ ** Conversion behaviors:**
126+ - ` int(3.9) ` → ` 3 ` (truncate towards zero)
127+ - ` int(-3.9) ` → ` -3 ` (truncate towards zero)
128+ - ` float(42) ` → ` 42.0 `
129+ - ` abs(-5) ` → ` 5 ` (preserves Int type)
130+ - ` abs(-3.14) ` → ` 3.14 ` (preserves Float type)
131+ - ` sqrt(16) ` → ` 4.0 ` (always Float)
132+
133+ ### List Primitives
134+
135+ | Function | Description |
136+ | ----------| -------------|
137+ | ` __list_length(lst) ` | Runtime primitive for list length. |
138+ | ` __list_get(lst, idx) ` | Runtime primitive for element access by index. |
139+ | ` __list_append(left, right) ` | Runtime primitive for list concatenation. |
140+ | ` __list_single(value) ` | Runtime primitive to create a single-element list. |
141+
142+ ### String Primitives
143+
144+ | Function | Description |
145+ | ----------| -------------|
146+ | ` __string_length(str) ` | Runtime primitive for string length. |
147+ | ` __string_append(s1, s2) ` | Runtime primitive for string concatenation. |
148+ | ` __substring(str, start, end) ` | Runtime primitive to extract substring. |
149+
51150## Using the Stdlib
52151
53152``` topineur
0 commit comments