Results for “fs.read”

18 results, best first

  1. definitionReference › Glossary effect Something a function does to the world outside the program: reading a file (fs), using the network (net), reading the clock (time). A function lists its effects after uses, so its first line tells…
  2. The language Effects …pure fn count_file(path: str): int! uses fs = word_count(fs.read(path)?) // reads a file fn main(args: [str]): ()! uses fs { print(count_file(args[1])?) }
  3. The language › Errors and optionals Errors: T! …up and then call something on the value, parenthesize: (fs.read(p)?).len(). x?.f() is optional chaining, which is for T? only. The compiler does not let an error vanish. Using a T! where a T is…
  4. The language › Effects The rule …count for the function it is written in. paths.map(p => fs.read(p)) needs uses fs on the enclosing function, and map itself stays pure. Top-level let constants and imprint values are computed without…
  5. packagePackages audio …Effects: none. Dependencies: none. let a = audio.decode(fs.read_bytes("take1.wav")?)? let clean = a.apply("highpass=f=80,acompressor=threshold=-20dB:ratio=3,loudnorm=I=-16")? let b =…
  6. packagePackages compress …Effects: none. Dependencies: none. let gz = compress.gzip(fs.read_bytes("log.txt")?) fs.write_bytes("log.txt.gz", gz)? let text = str.from_utf8(compress.gunzip(fs.read_bytes("log.txt.gz")?)?)? match…
  7. packagePackages csv …[["a", "b,c"], ["1", "say \"hi\""]] let recs = csv.records(fs.read("stock.csv")?)? // [{"name": "nut", "qty": "3", ...}] let items: [Item] = csv.decode(fs.read("stock.csv")?)? fs.write("out.csv",…
  8. packagePackages hash …check value. Effects: none. let digest = hash.sha256(fs.read_bytes("app.tar")?) // 32 bytes print(hash.sha256_hex("abc")) // ba7816bf8f01cfea... var h = hash.new_sha256() // streaming for chunk in…
  9. packagePackages json …Null]) print(json.pretty(v)) let ts: [Todo] = json.decode(fs.read("todos.json")?)? fs.write("todos.json", json.encode(ts))? match json.parse("[1,]") { err(e) => print(json.message(e)) // 1:4:…
  10. packagePackages toml …Map({"port": Int(8080)})}) let c: Config = toml.decode(fs.read("app.toml")?)? fs.write("app.toml", toml.encode(c)?)? match toml.parse("a: 1") { err(e) => print(toml.message(e)) // 1:2: expected '=',…
  11. packagePackages xml …Effects: none. Dependencies: none. let feed = xml.parse(fs.read("feed.xml")?)? for item in feed.descendants("item") { let title = item.child("title")?.text() else "(untitled)" print("{title}:…
  12. packagePackages yaml …List([Str("a"), Str("b")])}) let c: Config = yaml.decode(fs.read("app.yaml")?)? fs.write("app.yaml", yaml.encode(c))? match yaml.parse("a:\n\t- b") { err(e) => print(yaml.message(e)) // 2:1: tabs…
  13. Reference › Core library fs (uses fs) fs.read(path): str!, fs.write(path, text): ()!, fs.append(path, text): ()! whole files, as text fs.lines(path): [str]! fs.read_bytes(path): [int]!, fs.write_bytes(path, bytes): ()! bytes are ints 0…
  14. Reference › Cheat sheet Errors and optionals fn load(path: str): Config! uses fs { let text = fs.read(path)? // ? passes the error (or missing value) up parse(text)? } let c = load("a.toml") else e => default() // handle the error let n =…
  15. packagePackages › audio API Bytes are [int] (0–255), as in fs.read_bytes. Samples are planar floats, nominally -1.0..1.0. Times are in seconds, and levels in dB unless they are named gain or g.
  16. packagePackages › compress API Bytes are [int] (0–255), as in fs.read_bytes and core net. enum ZErr { Truncated, BadHeader(at: int, why: str), BadData(at: int, why: str), BadChecksum(what: str) }: at is a byte offset into the…
  17. packagePackages › splash Linked stylesheets and static files fn read_static(name: str): str? uses fs = match fs.read("static/{name}") { ok(text) => some(text) err(_) => none } fn handle(req: http.server.Req): http.Resp uses fs { match splash.static(req, f =>…
  18. error codeError codes › E0201: a T!/T? value used where a plain value is expected (missing ?) Common causes Calling a fallible function (fs.read, int.parse, xs.first()) without ? or else. In a function that can't fail itself, use else: int.parse(s) else 0.