gleam/erlang

Types

pub type Crash {
  Exited(Dynamic)
  Thrown(Dynamic)
  Errored(Dynamic)
}

Constructors

  • Exited(Dynamic)
  • Thrown(Dynamic)
  • Errored(Dynamic)

Error value returned by get_line function

pub type GetLineError {
  Eof
  NoData
}

Constructors

  • Eof
  • NoData
pub type TimeUnit {
  Second
  Millisecond
  Microsecond
  Nanosecond
}

Constructors

  • Second
  • Millisecond
  • Microsecond
  • Nanosecond

Functions

pub fn binary_to_term(binary: BitString) -> Result(Dynamic, Nil)
pub external fn erlang_timestamp() -> #(Int, Int, Int)

Returns the current OS system time as a tuple of Ints

http://erlang.org/doc/man/os.html#timestamp-0

pub fn format(term: a) -> String

Return a string representation of any term

pub external fn get_line(
  prompt: String,
) -> Result(String, GetLineError)

Reads a line from standard input with the given prompt.

Example

> get_line("Language: ")
// -> Language: <- gleam
Ok("gleam\n")
pub external fn rescue(fn() -> a) -> Result(a, Crash)

Gleam doesn’t offer any way to raise exceptions, but they may still occur due to bugs when working with unsafe code, such as when calling Erlang function.

This function will catch any error thrown and convert it into a result rather than crashing the process.

pub external fn system_time(TimeUnit) -> Int

Returns the current OS system time.

https://erlang.org/doc/apps/erts/time_correction.html#OS_System_Time

pub external fn term_to_binary(a) -> BitString
pub fn unsafe_binary_to_term(
  binary: BitString,
) -> Result(Dynamic, Nil)