Files and I/O builtins
13 builtins of Soma 3.2.4 in the category Files and I/O, with their exact signatures, as soma describe --builtins --json prints them.
- read_file
- write_file
- read_csv
- to_csv
- from_csv
- write_csv
- read_files
- par_read_files
- word_count
- par_word_count
- read_stdin
- write_str
print(args...) -> ()Print arguments space-separated, then a newline.
Used in verified programs:
- data/ab_test, line 42: print("A: {ra}%, B: {rb}%, lift: {l}pp")
- data/basket_analysis, line 41: for r in popularity() { print("{r.product}: {r.price_count}") }
- data/cohort_retention, line 41: print("{r.cohort}: {r.active_sum}/{r.active_count} = {r.retention_pct}%")
- data/csv_transform, line 32: for r in invoice() { print("{r.sku} x{r.qty}: net {r.net} + tax {r.tax} = {r.gross}") }
read_file
read_file(path: String) -> String | {error}Read a file as a string; returns {error: ...} on failure.
write_file
write_file(path: String, content) -> Bool | {error}Write content (stringified) to a file; true on success.
read_csv
read_csv(path: String, opts: Map?) -> List<Map> | {error}Parse an RFC 4180 CSV (quoted fields, "" escapes, multi-line quoted cells, CRLF) with a header row into maps. Unquoted cells are auto-typed Int/Float/String; a quoted cell and a leading-zero id (007) stay Strings; a short row is padded with "", extra fields are dropped. map("raw", true) keeps every cell as text (exact money: "1.00"); map("delimiter", ";") reads a ;-separated file; any other option is refused.
to_csv
to_csv(rows: List<Map>) -> StringThe CSV text write_csv would write (header from the first row; quoting that from_csv reads back exactly) — for a download without a temp file.
from_csv
from_csv(text: String, opts: Map?) -> List<Map>read_csv on CSV text already in memory (an uploaded body): same header, typing, raw and delimiter rules.
write_csv
write_csv(path: String, rows: List<Map>) -> Bool | {error}Write rows as CSV using the first row's keys as the header. A cell read_csv would split, trim or re-type is quoted (separators, quotes, newlines, edge spaces, and a String that reads as a number: "12" comes back "12"); a List/Map is its JSON text, () an empty cell; true comes back as the String "true".
read_files
read_files(dir: String, count: Int) -> List<{path, content}>Read the first count files of a directory, in file-name order, with their content (a file that is not UTF-8 text is skipped). There is no listing, move or delete: remember the names you processed in a slot.
par_read_files
par_read_files(dir: String, count: Int) -> List<{path, content}>Thread-parallel variant of read_files.
word_count
word_count(text: String | docs: List) -> Map<String, Int>Lowercased word frequency of a string or of {content} docs (Rust-speed).
par_word_count
par_word_count(docs: List) -> Map<String, Int>Thread-parallel variant of word_count over a list.
read_stdin
read_stdin() -> StringThe whole standard input (for soma run filters).
write_str
write_str(s: String) -> IntWrite s to stdout without a newline; returns the byte count.