From cff5a0dfa89ab3a7f95512382cedf88f8e1709d1 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 9 Dec 2022 18:16:41 +0200 Subject: Fix purity issue --- examples/impure-concept.milch | 2 +- examples/try.milch | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/impure-concept.milch b/examples/impure-concept.milch index 0a9af05..bf4f63b 100644 --- a/examples/impure-concept.milch +++ b/examples/impure-concept.milch @@ -24,4 +24,4 @@ ; error: cannot call impure function in pure context ; when calling function g! at examples/impure-concept.milch:21:14 ; in a function definition at examples/impure-concept.milch:21:11 -; when calling function h at examples/impure-concept.milch:23:1 \ No newline at end of file +; when calling function h at examples/impure-concept.milch:23:1 diff --git a/examples/try.milch b/examples/try.milch index 68d6cc2..561e716 100644 --- a/examples/try.milch +++ b/examples/try.milch @@ -1,6 +1,15 @@ (import "core/common") (import "core/result") +(let safe-read-file! (Result/safe! read-file!)) + ; 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") +(safe-read-file! "does-not-exist.txt") +(try! Result/ex (.! Result/ok read-file!) "examples/aoc22_1.txt") + +(let pure-fn (\[x] + (concat "foo" x))) + +(print! (pure-fn "bar\n")) +(print! "nice\n") -- cgit v1.3