Static copy
Copied from docs/guides/cookbook.md in https://github.com/poppy-team/ori-lang (MIT). Pinned to revision 42e1817227fbc96e8e4a4a85fac78b3fec0a0e0f, blob 4059814082934e4c1bc3d837497b1f58cc1a9c9a. The source repository remains canonical; this copy is refreshed through a sync pull request, not live.
Status: practical recipes for Ori S3 + inference B / workspace 0.3.8-devPortuguese: cookbook.pt-BR.md
module app.main
import ori.args as args
import ori.io as io
main()
const name = args.get_or(1, "Ori")
io.println("hello, " + name)
endori run main.orlmodule app.main
import ori.config as config
import ori.io as io
main()
const text: string = config.read_text_or("app.conf", "mode=dev")
io.println(text)
endUse config.read_json(path) for structured JSON (result / domain aliases).
module app.main
import ori.fs as fs
import ori.io as io
main()
match fs.write_text("out.txt", "done")
case ok(_):
match fs.read_text("out.txt")
case ok(value):
io.println(value)
case err(message):
io.eprintln(message)
end
case err(message):
io.eprintln(message)
end
endHelpers: fs.read_text_or, fs.write_text_result, domain aliases TextResult / IoResult via import ori.fs (TextResult, …).
module app.main
import ori.io as io
import ori.time as time
main()
const start: time.Instant = time.instant_now()
time.sleep_duration(time.duration_millis(10))
const elapsed: time.Duration = time.elapsed_since(start)
io.println(string(time.duration_to_millis(elapsed)))
endIn the app ori.proj:
[dependencies]
demo.math = { path = "../math", version = "0.1.0" }import demo.math (double)ori check main.orl
ori test main.orlori doc file main.orl --format html --out docs/api/index.html
ori doc check .Use .oridoc sidecars for long descriptions; keep inline comments short.
module app.main
import ori.io as io
import ori.net.http as http
main()
match http.get_plain("127.0.0.1", 8080, "/", 3000)
case ok(resp):
io.println(string(resp.status))
io.println(resp.body)
case err(msg):
io.eprintln(msg)
end
endTLS: http.get_tls("example.com", "/", 5000) (needs network; runtime rustls + ring).
Full sample: examples/http_get.
Also: build_request, parse_response for manual control.
import ori.io as io
main()
match io.open_output("out.txt")
case ok(out):
match io.write_text(out, "hi")
case ok(_):
match io.flush(out)
case ok(_):
io.close_output(out)
case err(_):
end
case err(_):
end
case err(_):
end
-- or: using out: ori.io.Output = out_handle (dispose closes the stream)
endmodule app.main
import ori.string as str
import ori.io as io
main()
const cleaned = " hi " |> str.trim
io.println(cleaned)
endPipe |> is typed as a normal call. Local const cleaned = … may omit the type when the checker knows the result (option B).
See also: Language tour · First project · Errors · Examples