Skip to content

Commit 136c250

Browse files
committed
API renovation
1 parent d1a4af2 commit 136c250

16 files changed

+121
-631
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## v1.0.0-rc1 - Unreleased
4+
5+
- The `gleam/erlang/os` module has been removed.
6+
- The `gleam/erlang` module has been removed.
7+
- The `gleam/erlang/reference` module has been created with the `Reference`
8+
type, and the `new` function.
9+
- In the `gleam/erlang/atom` module:
10+
- The `AtomNotLoaded` type has been removed.
11+
- The error type of `from_string` is now `Nil`.
12+
- The `from_string` function has been renamed to `get`.
13+
- The `create_from_string` function has been renamed to `create`.
14+
- The `gleam/erlang/application` module was created with:
15+
- The `priv_directory` function, formerly of the `gleam/erlang` module.
16+
- The `StartType` type.
17+
318
## v0.34.0 - 2025-02-02
419

520
- Fixed deprecation warnings with the Gleam standard library v0.53.0 or later.

src/gleam/erlang.gleam

Lines changed: 0 additions & 224 deletions
This file was deleted.

src/gleam/erlang/application.gleam

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// An Erlang application is a collection of code that can be loaded into the
2+
//// Erlang virtual machine and even started and stopped if they define a
3+
//// start module and supervision tree. Each Gleam package is an Erlang
4+
//// application.
5+
6+
import gleam/erlang/node.{type Node}
7+
8+
pub type StartType {
9+
/// A normal application start.
10+
Normal
11+
/// The application is distributed and started at the current node because of
12+
/// a takeover from Node, either because Erlang's `application:takeover/2`
13+
/// function has been called, or because the current node has higher priority
14+
/// than the previous node.
15+
Takeover(previous: Node)
16+
// The application is distributed and started at the current node because of
17+
// a failover from the previous node.
18+
Failover(previous: Node)
19+
}
20+
21+
/// Returns the path of an application's `priv` directory, where extra non-Gleam
22+
/// or Erlang files are typically kept. Each Gleam package is an Erlang
23+
/// application.
24+
///
25+
/// Returns an error if no application was found with the given name.
26+
///
27+
/// # Example
28+
///
29+
/// ```gleam
30+
/// application.priv_directory("my_app")
31+
/// // -> Ok("/some/location/my_app/priv")
32+
/// ```
33+
///
34+
@external(erlang, "gleam_erlang_ffi", "priv_directory")
35+
pub fn priv_directory(name: String) -> Result(String, Nil)

src/gleam/erlang/atom.gleam

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import gleam/dynamic.{type Dynamic}
2-
import gleam/dynamic/decode.{type DecodeError}
3-
41
/// Atom is a special string-like data-type that is most commonly used for
52
/// interfacing with code written in other BEAM languages such as Erlang and
63
/// Elixir. It is preferable to define your own custom types to use instead of
@@ -18,29 +15,13 @@ import gleam/dynamic/decode.{type DecodeError}
1815
///
1916
pub type Atom
2017

21-
/// An error returned when no atom is found in the virtual machine's atom table
22-
/// for a given string when calling the [`from_string`](#from_string) function.
23-
pub type FromStringError {
24-
AtomNotLoaded
25-
}
26-
27-
/// Finds an existing Atom for the given String.
18+
/// Finds an existing atom for the given string.
2819
///
29-
/// If no atom is found in the virtual machine's atom table for the String then
20+
/// If no atom is found in the virtual machine's atom table for the string then
3021
/// an error is returned.
3122
///
32-
/// ## Examples
33-
/// ```gleam
34-
/// from_string("ok")
35-
/// // -> Ok(create_from_string("ok"))
36-
/// ```
37-
/// ```gleam
38-
/// from_string("some_new_atom")
39-
/// // -> Error(AtomNotLoaded)
40-
/// ```
41-
///
4223
@external(erlang, "gleam_erlang_ffi", "atom_from_string")
43-
pub fn from_string(a: String) -> Result(Atom, FromStringError)
24+
pub fn get(a: String) -> Result(Atom, Nil)
4425

4526
/// Creates an atom from a string, inserting a new value into the virtual
4627
/// machine's atom table if an atom does not already exist for the given
@@ -52,34 +33,17 @@ pub fn from_string(a: String) -> Result(Atom, FromStringError)
5233
/// virtual machine to crash!
5334
///
5435
@external(erlang, "erlang", "binary_to_atom")
55-
pub fn create_from_string(a: String) -> Atom
36+
pub fn create(a: String) -> Atom
5637

5738
/// Returns a `String` corresponding to the text representation of the given
5839
/// `Atom`.
5940
///
6041
/// ## Examples
6142
/// ```gleam
62-
/// let ok_atom = create_from_string("ok")
43+
/// let ok_atom = create("ok")
6344
/// to_string(ok_atom)
6445
/// // -> "ok"
6546
/// ```
6647
///
6748
@external(erlang, "erlang", "atom_to_binary")
6849
pub fn to_string(a: Atom) -> String
69-
70-
/// Checks to see whether a `Dynamic` value is an atom, and return the atom if
71-
/// it is.
72-
///
73-
/// ## Examples
74-
/// ```gleam
75-
/// import gleam/dynamic
76-
/// from_dynamic(dynamic.from(create_from_string("hello")))
77-
/// // -> Ok(create_from_string("hello"))
78-
/// ```
79-
/// ```gleam
80-
/// from_dynamic(dynamic.from(123))
81-
/// // -> Error([DecodeError(expected: "Atom", found: "Int", path: [])])
82-
/// ```
83-
///
84-
@external(erlang, "gleam_erlang_ffi", "atom_from_dynamic")
85-
pub fn from_dynamic(from from: Dynamic) -> Result(Atom, List(DecodeError))

src/gleam/erlang/charlist.gleam

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
//// interfacing with Erlang, in particular when using older libraries that do
66
//// not accept binaries as arguments.
77

8-
/// A list of characters represented as ints. Commonly used by older Erlang
9-
/// modules.
8+
/// A list of characters represented as ints. Commonly used with Erlang
9+
/// functions that do not accept binary strings such as Gleam's core string
10+
/// type.
11+
///
1012
pub type Charlist
1113

12-
/// Transform a charlist to a string
14+
/// Convert a charlist to a string using Erlang's
15+
/// `unicode:characters_to_binary`.
16+
///
1317
@external(erlang, "unicode", "characters_to_binary")
1418
pub fn to_string(a: Charlist) -> String
1519

16-
// Calls `unicode:characters_to_binary(Data, unicode, unicode)`
17-
// Note: `unicode is an alias for utf8`
18-
// See <https://www.erlang.org/doc/man/unicode.html#characters_to_binary-1>
19-
20-
/// Transform a string to a charlist
20+
/// Convert a string to a charlist using Erlang's
21+
/// `unicode:characters_to_list`.
22+
///
2123
@external(erlang, "unicode", "characters_to_list")
2224
pub fn from_string(a: String) -> Charlist
23-
// Calls `unicode:characters_to_list(Data, unicode)`
24-
// Note: `unicode is an alias for utf8`
25-
// See <https://www.erlang.org/doc/man/unicode.html#characters_to_list-1>

0 commit comments

Comments
 (0)