diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-09 15:53:16 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-09 15:53:16 +0200 |
| commit | 47c2eca7dceae9fb4e6f687f70273fb262fa07a2 (patch) | |
| tree | 81554c139448a602a4e4126ca53e322c38c06cfa /examples | |
| parent | d64c5725d79195fc6ef0472d4efa55737ebc00c3 (diff) | |
Add try! builtin
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/atom-concept.milch | 11 | ||||
| -rw-r--r-- | examples/try.milch | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/examples/atom-concept.milch b/examples/atom-concept.milch new file mode 100644 index 0000000..4158b45 --- /dev/null +++ b/examples/atom-concept.milch @@ -0,0 +1,11 @@ +(let state (atom! 10)) + +(let do-loop! (\![i n] + (match true + (lt? i n) (do (update! dec state) + (do-loop! (inc i) n)) + otherwise unit))) + +(do-loop! 0 5) +(get! state) +; => 5 diff --git a/examples/try.milch b/examples/try.milch new file mode 100644 index 0000000..68d6cc2 --- /dev/null +++ b/examples/try.milch @@ -0,0 +1,6 @@ +(import "core/common") +(import "core/result") + +; calls read-file! and wraps the result in a Result/ok on success +; in case of error, calls Result/ex on the error string +(try! Result/ex (. Result/ok read-file!) "does-not-exist.txt") |
