tur/effects
standard algebraic effects for IO, logging, and randomness.
Since: Phase 19
with-write
(with-write [body])
handle the Write effect by printing to stdout via println.
| body | the expression whose Write effects are handled |
the return value of body
(with-write (perform (Write "hello"))) ; prints "hello"
Since: Phase 19
with-fail-panic
(with-fail-panic [body])
handle the Fail effect by panicking with the message.
| body | the expression whose Fail effects are handled |
the return value of body, or panics on Fail
(with-fail-panic (perform (Fail "oops"))) ; panics with "oops"
Since: Phase 19
with-getenv
(with-getenv [body])
handle the GetEnv effect by delegating to C getenv(3).
| body | the expression whose GetEnv effects are handled |
the return value of body
(with-getenv (perform (GetEnv "PATH"))) ; => "/usr/bin:..."
Since: Phase 19
read-int-console
(read-int-console)
read a single integer from stdin via scanf.
int -- the integer read from stdin
(read-int-console) ; => 7
Since: Phase 19
with-read-console
(with-read-console [body])
handle the Read effect by reading an integer from stdin.
| body | the expression whose Read effects are handled |
the return value of body
(with-read-console (perform (Read))) ; reads integer from stdin
Since: Phase 19
with-stderr-log
(with-stderr-log [body])
handle the Log effect by printing all messages to stdout.
| body | the expression whose Log effects are handled |
the return value of body
(with-stderr-log (perform (Log "warn" "low memory"))) ; prints "low memory"
Since: Phase 19
with-silent-log
(with-silent-log [body])
handle the Log effect by suppressing all log output.
| body | the expression whose Log effects are handled |
the return value of body
(with-silent-log (perform (Log "debug" "ignored"))) ; no output
Since: Phase 19
with-abort-panic
(with-abort-panic [body])
handle the Abort effect by panicking with the message.
| body | the expression whose Abort effects are handled |
the return value of body, or panics on Abort
(with-abort-panic (perform (Abort "fatal"))) ; panics with "fatal"
Since: Phase 19
with-async
(with-async [body])
handle the Async effect by running the thunk and resuming with its result.
| body | the expression whose Async effects are handled |
the return value of body
(with-async (perform (Async my-thunk))) ; runs thunk inline
Since: Phase T25
with-await
(with-await [body])
handle the Await effect by blocking until the future resolves.
| body | the expression whose Await effects are handled |
the return value of body
(with-await (perform (Await my-future))) ; => resolved value
Since: Phase T25