Builtins
Soma 3.2.4 has 252 builtins. This list is generated from the compiler (soma describe --builtins --json), so a name that is not here is not a builtin — an agent should never guess one.
| Builtin | Signature |
|---|---|
| Strings | |
| concat | concat(a, b) -> String | concat(a: List, b: List) -> List |
| pad_left | pad_left(s, width: Int, fill?: String) -> String |
| pad_right | pad_right(s, width: Int, fill?: String) -> String |
| split | split(s: String, delim: String) -> List<String> |
| replace | replace(s: String, old: String, new: String) -> String |
| contains | contains(haystack: String, needle: String) -> Bool | contains(list: List, x) -> Bool | contains(m: Map, key) -> Bool |
| starts_with | starts_with(s: String, prefix: String) -> Bool |
| ends_with | ends_with(s: String, suffix: String) -> Bool |
| lowercase | lowercase(s: String) -> String |
| uppercase | uppercase(s: String) -> String |
| trim | trim(s: String) -> String | trim(s: String, chars: String) -> String |
| sha256 | sha256(s: String) -> String |
| hmac_sha256 | hmac_sha256(key: String, message: String) -> String |
| random_token | random_token(bytes?: Int) -> String |
| secure_eq | secure_eq(a: String, b: String) -> Bool |
| format | format(fmt: String, args...) -> String |
| fields | fields(s: String) -> List<String> |
| index_of | index_of(s: String, sub: String) -> Int | index_of(xs: List, x) -> Int |
| substring | substring(s: String, start: Int, end: Int) -> String |
| escape_html | escape_html(s: String) -> String |
| str_len | str_len(s: String) -> Int |
| str_at | str_at(s: String, i: Int) -> Int |
| str_eq | str_eq(a: String, b: String) -> Bool |
| chr | chr(n: Int) -> String |
| ord | ord(s: String) -> Int |
| regex_count | regex_count(text: String, pattern: String) -> Int |
| regex_match | regex_match(text: String, pattern: String) -> Int |
| regex_replace | regex_replace(text: String, pattern: String, replacement: String) -> String |
| Math | |
| to_fixed | to_fixed(x: Float, digits: Int) -> String |
| div_round | div_round(n: Int, d: Int) -> Int |
| floor_div | floor_div(a: Int, b: Int) -> Int |
| mod | mod(a: Int, b: Int) -> Int |
| divmod | divmod(a: Int, b: Int) -> [q, r] |
| abs | abs(x: Int|Float) -> Int|Float |
| round | round(x: Float) -> Int | round(x: Float, digits: Int) -> Float |
| floor | floor(x: Float) -> Int |
| ceil | ceil(x: Float) -> Int |
| sqrt | sqrt(x: Int|Float) -> Float |
| sin | sin(x: Int|Float) -> Float |
| cos | cos(x: Int|Float) -> Float |
| tan | tan(x: Int|Float) -> Float |
| atan | atan(x: Int|Float) -> Float |
| atan2 | atan2(y: Float, x: Float) -> Float |
| asin | asin(x: Float) -> Float |
| acos | acos(x: Float) -> Float |
| pi | pi() -> Float |
| log | log(x: Int|Float) -> Float |
| ln | ln(x: Int|Float) -> Float |
| exp | exp(x: Int|Float) -> Float |
| log10 | log10(x: Int|Float) -> Float |
| pow | pow(base: Int|Float, exp: Int|Float) -> Float |
| ipow | ipow(base: Int, exp: Int) -> Int |
| min | min(a, b) -> Int|Float | min(list: List) -> Int|Float |
| max | max(a, b) -> Int|Float | max(list: List) -> Int|Float |
| sum | sum(list: List) -> Int|Float |
| product | product(list: List) -> Int|Float |
| avg | avg(list: List) -> Int|Float |
| parse_int | parse_int(s: String, base: Int?) -> Int | () |
| parse_float | parse_float(s: String) -> Float | () |
| idiv | idiv(a: Int, b: Int) -> Int |
| clamp | clamp(v, lo, hi) -> Int|Float |
| random | random() -> Float | random(max: Int) -> Int | random(min: Int, max: Int) -> Int |
| gcd | gcd(a: Int, b: Int) -> Int |
| sqrt_int | sqrt_int(n: Int) -> Int |
| pow_mod | pow_mod(base: Int, exp: Int, m: Int) -> Int |
| band | band(a: Int, b: Int) -> Int |
| bor | bor(a: Int, b: Int) -> Int |
| bxor | bxor(a: Int, b: Int) -> Int |
| bnot | bnot(a: Int) -> Int |
| shl | shl(a: Int, n: Int) -> Int |
| shr | shr(a: Int, n: Int) -> Int |
| bit_test | bit_test(a: Int, i: Int) -> Int |
| bit_set | bit_set(a: Int, i: Int) -> Int |
| bit_clr | bit_clr(a: Int, i: Int) -> Int |
| bit_next | bit_next(a: Int, i: Int) -> Int |
| bit_len | bit_len(a: Int) -> Int |
| median | median(xs: List) -> Int | Float |
| pstdev | pstdev(xs: List) -> Float |
| stddev | stddev(xs: List) -> Float |
| stdev | stdev(xs: List) -> Float |
| variance | variance(xs: List) -> Float |
| pvariance | pvariance(xs: List) -> Float |
| Collections | |
| list | list(items...) -> List |
| map | map(key, value, ...) -> Map | list |> map(x => expr) -> List |
| push | push(list: List, items...) -> List |
| nth | nth(list: List, i: Int) -> Any |
| reverse | reverse(list: List) -> List |
| range | range(start: Int, end: Int, step?: Int) -> List<Int> |
| sort | sort(list: List, order?: "desc") -> List |
| flatten | flatten(list: List) -> List |
| zip | zip(a: List, b: List) -> List<{left, right}> |
| enumerate | enumerate(list: List) -> List<{index, value}> |
| with | with(m: Map, key, value, ...) -> Map | with(list: List, i: Int, value) -> List |
| without | without(m: Map, keys...) -> Map |
| merge | merge(a: Map, b: Map, ...) -> Map |
| join | join(list: List, sep: String) -> String | join(left: List, right: List, key) -> List |
| slice | slice(xs: List|String, start: Int, end?: Int) -> List|String |
| keys | keys(m: Map) -> List<String> |
| values | values(m: Map) -> List |
| entries | entries(m: Map) -> List<{key, value}> |
| Pipelines | |
| filter_by | filter_by(rows: List<Map>, field, value) -> List<Map> | filter_by(rows: List<Map>, field, op: ">"|">="|"<"|"<="|"=="|"!=", value) -> List<Map> |
| sort_by | sort_by(rows: List<Map>, field, order?: "desc") -> List<Map> | sort_by(list, x => key, order?: "desc") -> List |
| top | top(rows: List, n: Int) -> List |
| bottom | bottom(rows: List, n: Int) -> List |
| sum_by | sum_by(rows: List<Map>, field) -> Int | Float |
| avg_by | avg_by(rows: List<Map>, field) -> Int|Float |
| min_by | min_by(rows: List<Map>, field) -> Map |
| max_by | max_by(rows: List<Map>, field) -> Map |
| pluck | pluck(rows: List<Map>, field) -> List |
| group_by | group_by(rows: List<Map>, field) -> Map<String, List> |
| distinct | distinct(rows: List, field?) -> List |
| distinct_by | distinct_by(rows: List<Map>, field: String) -> List<Map> |
| count_by | count_by(rows: List<Map>, field, value) -> Int |
| select | select(rows: List<Map>, fields...) -> List<Map> |
| agg | agg(rows: List<Map>, group_field, "col:func"...) -> List<Map> |
| inner_join | inner_join(left: List<Map>, right: List<Map>, key) -> List<Map> |
| left_join | left_join(left: List<Map>, right: List<Map>, key) -> List<Map> |
| Lambdas | |
| filter | filter(list: List, x => Bool) -> List |
| find | find(list: List, x => Bool) -> Any |
| any | any(list: List, x => Bool) -> Bool |
| all | all(list: List, x => Bool) -> Bool |
| count | count(list: List, x => Bool) -> Int |
| reduce | reduce(list: List, initial, p => expr) -> Any |
| Types and conversion | |
| len | len(x: String|List|Map) -> Int |
| to_string | to_string(x) -> String |
| to_int | to_int(x) -> Int |
| to_float | to_float(x) -> Float |
| to_json | to_json(x) -> String |
| from_json | from_json(s: String) -> Any |
| type_of | type_of(x) -> String |
| is_type | is_type(value: Map, type_name: String) -> Bool |
| is_a | is_a(value: Map, type_name: String) -> Bool |
| fail | fail(kind: String, detail?) -> never | fail(r: TryResult) -> never |
| Files and I/O | |
| print(args...) -> () | |
| read_file | read_file(path: String) -> String | {error} |
| write_file | write_file(path: String, content) -> Bool | {error} |
| read_csv | read_csv(path: String, opts: Map?) -> List<Map> | {error} |
| to_csv | to_csv(rows: List<Map>) -> String |
| from_csv | from_csv(text: String, opts: Map?) -> List<Map> |
| write_csv | write_csv(path: String, rows: List<Map>) -> Bool | {error} |
| read_files | read_files(dir: String, count: Int) -> List<{path, content}> |
| par_read_files | par_read_files(dir: String, count: Int) -> List<{path, content}> |
| word_count | word_count(text: String | docs: List) -> Map<String, Int> |
| par_word_count | par_word_count(docs: List) -> Map<String, Int> |
| read_stdin | read_stdin() -> String |
| write_str | write_str(s: String) -> Int |
| Time | |
| parse_date | parse_date(s: "YYYY-MM-DD") -> {year, month, day, weekday, epoch_day} |
| add_days | add_days(date: String, n: Int) -> String |
| add_months | add_months(date: String, n: Int) -> String |
| days_between | days_between(a: String, b: String) -> Int |
| months_between | months_between(a: String, b: String) -> Int |
| days_in_month | days_in_month(year: Int, month: Int) -> Int |
| now | now() -> Int |
| now_ms | now_ms() -> Int |
| today | today() -> String |
| format_date | format_date(ts: Int) -> String |
| sleep | sleep(ms: Int) -> () |
| HTTP client | |
| http_get | http_get(url: String, opts?: {timeout, max_bytes, headers}) -> Map|List|String |
| http_post | http_post(url: String, body, opts?: {timeout, max_bytes, headers}) -> Map|List|String |
| http_put | http_put(url: String, body, opts?) -> Map|List|String |
| http_patch | http_patch(url: String, body, opts?) -> Map|List|String |
| http_delete | http_delete(url: String, opts?) -> Map|List|String |
| ws_connect | ws_connect(url: String) -> Map |
| ws_send | ws_send(msg) -> () |
| link | link(addr: "host:port") -> () |
| subscribe | subscribe(url: String) -> () |
| refusal | refusal(kind: String, detail?: String) -> Map |
| Web responses | |
| html | html(body) -> Response | html(status: Int, body, header_key, header_value, ...) -> Response |
| response | response(status: Int, body, header_key, header_value, ...) -> Response |
| redirect | redirect(url: String) -> Response |
| sse | sse(streams...) -> Response |
| publish | publish(stream: String, data) -> () |
| Templates | |
| load_template | load_template(path: String, key, value, ...) -> String |
| load | load(path: String, key, value, ...) -> String |
| include | include(path: String, key, value, ...) -> String |
| render | render(template: String, key, value, ...) -> String |
| render_each | render_each(rows: List<Map>, template: String) -> String |
| Agents and LLM calls | |
| think | think(prompt: String, system?: String, opts?: {max_tokens, timeout, max_rounds, tools_allowed, requires}) -> String |
| think_json | think_json(prompt: String, system?: String, opts?: {as, max_tokens, timeout, max_rounds, tools_allowed, requires}) -> Map | the `cell type` named by `as` |
| horde | horde(handler, inputs: List, opts?: {concurrency, max_attempts, budget_tokens, seed, snapshot, instance, on_result, apply, on_done, on_error}) -> String |
| vote | vote(handler, input, k: Int) -> Map |
| horde_status | horde_status(id: String) -> Map |
| horde_results | horde_results(id: String) -> List |
| horde_cancel | horde_cancel(id: String) -> Bool |
| delegate | delegate(cell: String, signal: String, args...) -> Any |
| set_budget | set_budget(max_tokens: Int) -> () |
| tokens_used | tokens_used() -> Int |
| tokens_remaining | tokens_remaining() -> Int |
| trace | trace() -> List |
| clear_trace | clear_trace() -> () |
| clear_context | clear_context() -> () |
| approve | approve(action: String) -> Bool |
| resume | resume(wait_id: String, answer) -> Any |
| deliver | deliver(name: String, key, value) -> Any |
| waiting | waiting() -> List<Map> |
| cancel_wait | cancel_wait(wait_id: String) -> Bool |
| State machines | |
| next_id | next_id() -> Int |
| transition | transition(id, target_state: String) -> {id, from, to} | transition(id, from_state: String, to_state: String) -> {id, from, to} |
| get_status | get_status(id) -> String |
| has_state | has_state(id) -> Bool |
| valid_transitions | valid_transitions(id) -> List<String> |
| Memory | |
| remember | remember(key, value) -> () |
| recall | recall(key: String) -> Any |
| append | slot.append(value) -> () |
| Native code | |
| buffer | buffer(n: Int) -> Buf [native] only |
| buf_get | buf_get(b: Buf, i: Int) -> Int [native] only |
| buf_set | buf_set(b: Buf, i: Int, v: Int) -> () [native] only |
| buffer_f | buffer_f(n: Int) -> BufF [native] only |
| buf_get_f | buf_get_f(b: BufF, i: Int) -> Float [native] only |
| buf_set_f | buf_set_f(b: BufF, i: Int, v: Float) -> () [native] only |
| hashmap | hashmap() -> HMap [native] only |
| hm_get | hm_get(m: HMap, k: Int) -> Int [native] only |
| hm_set | hm_set(m: HMap, k: Int, v: Int) -> () [native] only |
| hm_inc | hm_inc(m: HMap, k: Int) -> () [native] only |
| hm_len | hm_len(m: HMap) -> Int [native] only |
| hm_has | hm_has(m: HMap, k: Int) -> Bool [native] only |
| strbuf | strbuf(capacity?: Int) -> SBuf [native] only |
| sb_push | sb_push(b: SBuf, s: String) -> () [native] only |
| sb_push_int | sb_push_int(b: SBuf, n: Int) -> () [native] only |
| sb_push_char | sb_push_char(b: SBuf, c: Int) -> () [native] only |
| sb_len | sb_len(b: SBuf) -> Int [native] only |
| sb_finish | sb_finish(b: SBuf) -> String [native] only |
| Linear algebra and risk | |
| matrix | matrix("1 2; 3 4") -> List<List<Float>> |
| mat | mat(rows: Int, cols: Int, values: List<Float>) -> List<List<Float>> |
| reshape | reshape(values, rows: Int, cols: Int) -> Matrix |
| transpose | transpose(m: Matrix) -> Matrix |
| shape | shape(m) -> List<Int> |
| matmul | matmul(a: Matrix, b: Matrix) -> Matrix |
| det | det(m: Matrix) -> Float |
| diag_sum | diag_sum(m: Matrix) -> Float |
| identity | identity(n: Int) -> Matrix |
| scale | scale(m: Matrix, k) -> Matrix |
| flatten_mat | flatten_mat(m: Matrix) -> List<Float> |
| rows | rows(r1: List<Float>, r2: List<Float>, ...) -> List<List<Float>> |
| cols | cols(c1: List<Float>, c2: List<Float>, ...) -> List<List<Float>> |
| eye | eye(n: Int) -> List<List<Float>> |
| zeros | zeros(r: Int, c: Int) -> List<List<Float>> |
| ones | ones(r: Int, c: Int) -> List<List<Float>> |
| diag | diag(values: List<Float>) -> List<List<Float>> |
| to_sampled | to_sampled(A: List<List<Float>>, opts?: {max_rows, max_cols}) -> Map |
| sample_row | sample_row(A) -> Map |
| drop_sampled | drop_sampled(handle: Map) -> Bool |
| importance_sample_rows | importance_sample_rows(A, opts: {samples, max_dim}) -> Map |
| svd_lowrank | svd_lowrank(A, opts: {row_samples, col_samples, rank, max_dim}) -> Map |
| regress_sgd | regress_sgd(A, b: List<Float>, opts: {eps, eta, lambda, max_iter, rigorous, samples_per_iter, max_dim}) -> Map |
| clean_covariance | clean_covariance(returns: List<List<Float>>, opts: {method: "rie"|"clip"|"raw", eta, center, max_assets, max_obs}) -> Map |
| impact_sqrt | impact_sqrt(qty: Float, daily_volume: Float, sigma: Float, opts?: {Y}) -> Map |
| quantile | quantile(values: List<Float>, q: Float) -> Float |
| var_historical | var_historical(returns: List<Float>, opts?: {alpha, max_obs}) -> Float |
| expected_shortfall_historical | expected_shortfall_historical(returns: List<Float>, opts?: {alpha, max_obs}) -> Float |
| var_gaussian | var_gaussian(returns: List<Float>, opts?: {alpha, mu, sigma, max_obs}) -> Float |
| Internal | |
| _coalesce | _coalesce(a, b) -> Any |