gleam/erlang

Types

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

Constructors

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

Constructors

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

Error value returned by get_line function

pub type GetLineError {
  Eof
  NoData
}

Constructors

  • 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 refernces in the Erlang documentation.

pub external type Reference
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 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

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 make_reference() -> Reference

Create a new unique reference.

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 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,
)
Search Document