soma.cell

File I/O

File I/O, in the reference of the Soma programming language (soma 3.2.4). A block marked ✓ is a whole program that soma check accepts; the others are excerpts.

let content = read_file("data.txt")
write_file("output.txt", content)
let rows = read_csv("data.csv")       // list of maps, auto-typed
write_csv("out.csv", rows)            // list of maps → CSV (headers from first row)
let tpl = load("page.html")           // read file (aliases: include, load_template)
let s = load("page.html", "k", v)     // read + replace {k} placeholders with v
let files = read_files("dir", 100)        // first N files → list of {path, content}
let files = par_read_files("dir", 100)    // parallel version (threaded)
let counts = word_count(text)             // map of word → count (lowercased; also takes a list)
let counts = par_word_count(files)        // parallel version (threaded)