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 runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | import std/io |
| 2 | |
| 3 | // A panic unwinds through cleanups too. A cleanup that panics while a |
| 4 | // `final ctl` operation unwinds replaces that unwinding (ADR 0016). |
| 5 | |
| 6 | effect fail |
| 7 | { |
| 8 | final ctl fail :: reason: String -> Never |
| 9 | } |
| 10 | |
| 11 | fn attempt :: action: fn() -> a / <fail | e> -> Result<a, String> / <e> |
| 12 | { |
| 13 | handle |
| 14 | { |
| 15 | Ok(action ()) |
| 16 | } |
| 17 | with |
| 18 | { fail reason -> Error(reason) } |
| 19 | } |
| 20 | |
| 21 | pub fn main :: -> () / <io> |
| 22 | { |
| 23 | defer io.println "main cleaned up" |
| 24 | io.println "start" |
| 25 | let r: Result<Int, String> = |
| 26 | attempt |
| 27 | fn |
| 28 | { |
| 29 | defer io.println "outer cleanup still runs" |
| 30 | defer panic "cleanup failed" |
| 31 | fail "never caught" |
| 32 | } |
| 33 | match r |
| 34 | { Ok(_) -> io.println "not reached" |
| 35 | , Error(e) -> io.println ("not reached either: " <> e) |
| 36 | } |
| 37 | } |
| 38 | //> start |
| 39 | //> outer cleanup still runs |
| 40 | //> main cleaned up |
| 41 | //! panic: cleanup failed |