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

A unique reference value.

It holds no particular meaning or value, but unique values are often useful in programs are used heavily within both Gleam and Erlang’s OTP frameworks.

More can be read about references in the Erlang documentation.

pub type Reference
pub type TimeUnit {


  • Second
  • Millisecond
  • Microsecond
  • Nanosecond


pub fn binary_to_term(binary: BitArray) -> Result(Dynamic, Nil)
pub fn ensure_all_started(
  application 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 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 fn get_line(
  prompt prompt: String,
) -> Result(String, GetLineError)

Reads a line from standard input with the given prompt.


get_line(“Language: “) // -> Language: <- gleam Ok(“gleam\n”)

pub fn make_reference() -> Reference

Create a new unique reference.

pub fn priv_directory(name: String) -> Result(String, Nil)

Returns the path of a package’s priv directory, where extra non-Gleam or Erlang files are typically kept.

Returns an error if no package was found with the given name.


> erlang.priv_directory("my_app")
// -> Ok("/some/location/my_app/priv")
pub fn rescue(a: 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 fn start_arguments() -> List(String)

Deprecated: Please use the argv package instead

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

This is sometimes called argv in other languages.

pub fn system_time(a: TimeUnit) -> Int
pub fn term_to_binary(a: a) -> BitArray
pub fn unsafe_binary_to_term(
  binary: BitArray,
) -> Result(Dynamic, Nil)
Search Document