soma.cell

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.

print

print(args...) -> ()

Print arguments space-separated, then a newline.

deterministic · replay: pure

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.

deterministic · replay: an effect: not in the log — replay calls it again

write_file

write_file(path: String, content) -> Bool | {error}

Write content (stringified) to a file; true on success.

deterministic · replay: an effect: not in the log — replay calls it again

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.

deterministic · replay: an effect: not in the log — replay calls it again

to_csv

to_csv(rows: List<Map>) -> String

The 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.

deterministic · replay: pure

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.

deterministic · replay: pure

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".

deterministic · replay: an effect: not in the log — replay calls it again

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.

deterministic · replay: an effect: not in the log — replay calls it again

par_read_files

par_read_files(dir: String, count: Int) -> List<{path, content}>

Thread-parallel variant of read_files.

deterministic · replay: pure

word_count

word_count(text: String | docs: List) -> Map<String, Int>

Lowercased word frequency of a string or of {content} docs (Rust-speed).

deterministic · replay: pure

par_word_count

par_word_count(docs: List) -> Map<String, Int>

Thread-parallel variant of word_count over a list.

deterministic · replay: pure

read_stdin

read_stdin() -> String

The whole standard input (for soma run filters).

deterministic · replay: an effect: not in the log — replay calls it again

write_str

write_str(s: String) -> Int

Write s to stdout without a newline; returns the byte count.

deterministic · replay: an effect: not in the log — replay calls it again