Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

WasiCli

1 type6 functions

Reading and writing a command-line program's standard streams, its arguments, its environment variables, and its exit, for a WASI preview1 host. The wasip2 package's WasiCli, preloaded on the component target instead, has print, args, env and exit, with exit reaching the host as success or failure only.

_start = () -> match WasiCli.readLine() {
  Ok(line) -> WasiCli.print(String.concat(line, "\n"))
  Err(EndOfInput) -> WasiCli.exit(0)
}

At a glance

  • Result

    Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

  • print

    Writes the string to stdout, exactly as it is: no newline is added.

  • readAll

    Everything left on stdin, read to the end of input.

  • readLine

    The next line of stdin, without its \n or \r\n.

  • exit

    Stop the program with code as its exit status.

  • args

    The program's arguments, starting with the program's own path as the host gives it.

  • env

    The value of the environment variable name, everything after the first = of its entry, or Err(NotFound) when the environment has none.

Types

Result

Result(a, e) = [Ok(a) | Err(e)]

Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

Functions

print

(String) -> Unitimpure

Writes the string to stdout, exactly as it is: no newline is added.

readAll

() -> Stringimpure

Everything left on stdin, read to the end of input.

readLine

() -> Result(String, [EndOfInput | e])impure

The next line of stdin, without its \n or \r\n. An empty line is Ok(""), and a closed stdin is Err(EndOfInput), so a loop can tell the two apart. A last line with no terminator is still Ok; the end of input is reported on the call after it.

exit

(Int) -> aimpure

Stop the program with code as its exit status. It does not return, so its result is any type the call stands in for.

args

() -> List(String)impure

The program's arguments, starting with the program's own path as the host gives it.

env

(String) -> Result(String, [NotFound | e])impure

The value of the environment variable name, everything after the first = of its entry, or Err(NotFound) when the environment has none.

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.