Skip to content

Commit 68fa921

Browse files
committed
Define how to_existing_atom works within modules, closes #11786
1 parent abda4a1 commit 68fa921

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/elixir/lib/list.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,14 +949,22 @@ defmodule List do
949949
end
950950

951951
@doc """
952-
Converts a charlist to an existing atom. Raises an `ArgumentError`
953-
if the atom does not exist.
952+
Converts a charlist to an existing atom.
954953
955954
Elixir supports conversions from charlists which contains any Unicode
956-
code point.
955+
code point. Raises an `ArgumentError` if the atom does not exist.
957956
958957
Inlined by the compiler.
959958
959+
> #### Atoms and modules {: .info}
960+
>
961+
> Since Elixir is a compiled language, the atoms defined in a module
962+
> will only exist after said module is loaded, which typically happens
963+
> whenever a function in the module is executed. Therefore, it is
964+
> generally recommended to call `List.to_existing_atom/1` only to
965+
> convert atoms defined within the module making the function call
966+
> to `to_existing_atom/1`.
967+
960968
## Examples
961969
962970
iex> _ = :my_atom

lib/elixir/lib/string.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,9 +2569,19 @@ defmodule String do
25692569
Converts a string to an existing atom.
25702570
25712571
The maximum atom size is of 255 Unicode code points.
2572+
Raises an `ArgumentError` if the atom does not exist.
25722573
25732574
Inlined by the compiler.
25742575
2576+
> #### Atoms and modules {: .info}
2577+
>
2578+
> Since Elixir is a compiled language, the atoms defined in a module
2579+
> will only exist after said module is loaded, which typically happens
2580+
> whenever a function in the module is executed. Therefore, it is
2581+
> generally recommended to call `String.to_existing_atom/1` only to
2582+
> convert atoms defined within the module making the function call
2583+
> to `to_existing_atom/1`.
2584+
25752585
## Examples
25762586
25772587
iex> _ = :my_atom

0 commit comments

Comments
 (0)