tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

28 lignes · 856 octetsBrut · Historique
1// Whole-file IO (std/file, ADR 0049): write, then read back; a missing
2// file is an `Error`, not a panic. The file is never deleted (both
3// backends may run this program at the same time), in the temp dir.
4
5import std/file
6import std/io
7import std/option
8import std/os
9
10pub fn main :: -> () / <io>
11{
12 let path =
13 option.unwrap_or (os.env "TMPDIR") "/tmp" <> "/louise_run_file_test.txt"
14 // Never created by this program: `exists` is `False` even on a rerun.
15 let missing = path <> ".nope"
16 io.println (show (file.exists missing))
17 io.println (show (file.write path "hello file"))
18 io.println (show (file.exists path))
19 io.println (show (file.size path))
20 io.println (show (file.read path))
21 io.println (show (file.read missing))
22}
23//> False
24//> Ok(())
25//> True
26//> Ok(10)
27//> Ok(hello file)
28//> Error(No such file or directory (os error 2))