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.
Dernier runEn cours#127 · main
0Étoiles
0Forks
40Issues
| 1 | // Standard input line by line (ADR 0086), from stdin_lines.stdin: a CRLF |
| 2 | // line loses its "\r" too, a lone "\r" stays, an empty line is a line, and |
| 3 | // a last line without newline is still one. Input then ends, for every |
| 4 | // later read. |
| 5 | |
| 6 | import std/io |
| 7 | |
| 8 | fn shown :: r: Result<Option<String>, io.Error> -> String |
| 9 | { |
| 10 | match r |
| 11 | { Ok(Some(line)) -> "line " <> debug line |
| 12 | , Ok(None) -> "end" |
| 13 | , Error(e) -> "error " <> show e |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | fn lines :: -> () / <io> |
| 18 | { |
| 19 | let r = io.read_line () |
| 20 | io.println (shown r) |
| 21 | match r { Ok(Some(_)) -> lines (), _ -> () } |
| 22 | } |
| 23 | |
| 24 | pub fn main :: -> () / <io> |
| 25 | { |
| 26 | lines () |
| 27 | io.println ("again: " <> shown (io.read_line ())) |
| 28 | match io.read_bytes 10 |
| 29 | { Ok(None) -> io.println "bytes: end", _ -> io.println "bytes: more?" } |
| 30 | } |
| 31 | //> line "first" |
| 32 | //> line "second, CRLF" |
| 33 | //> line "" |
| 34 | //> line " spaced " |
| 35 | //> line "a\rb" |
| 36 | //> line "été" |
| 37 | //> line "last, no newline" |
| 38 | //> end |
| 39 | //> again: end |
| 40 | //> bytes: end |