pub type Crash {


  • Exited(Dynamic)
  • Thrown(Dynamic)
  • Errored(Dynamic)
pub type EnsureAllStartedError {
  UnknownApplication(name: Atom)
  ApplicationFailedToStart(name: Atom, reason: Dynamic)


  • UnknownApplication(name: Atom)
  • ApplicationFailedToStart(name: Atom, reason: Dynamic)

Error value returned by get_line function

pub type GetLineError {


  • Eof
  • NoData
pub type TimeUnit {


  • Second
  • Millisecond
  • Microsecond
  • Nanosecond


pub fn binary_to_term(binary: BitString) -> Result(Dynamic, Nil)
pub external fn ensure_all_started(
  application: Atom,
) -> Result(List(Atom), EnsureAllStartedError)

Starts an OTP application’s process tree in the background, as well as the trees of any applications that the given application depends upon. An OTP application typically maps onto a Gleam or Hex package.

Returns a list of the applications that were started. Calling this function for application that have already been started is a no-op so you do not need to check the application state beforehand.

In Gleam we prefer to not use these implicit background process trees, but you will likely still need to start the trees of OTP applications written in other BEAM languages such as Erlang or Elixir, including those included by default with Erlang/OTP.

For more information see the OTP documentation.

pub external fn erlang_timestamp() -> #(Int, Int, Int)

Returns the current OS system time as a tuple of Ints

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.


> get_line("Language: ")
// -> Language: <- gleam
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 sleep(Int) -> Nil

Suspends the process calling this function for the specified number of milliseconds.

pub external fn sleep_forever() -> Nil

Suspends the process calling this function for the specified number of milliseconds.

pub fn start_arguments() -> List(String)

Get the arguments given to the program when it was started.

This is sometimes called argv in other languages.

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