I’m improving some documentation in Elixir, and in order to do so, I need to dynamically build a list of atoms, but without using string interpolation.
so :#{variable} is not what I am looking for, neither String.to_atom/1, nor List.to_atom/1, as I am trying to test the use of atoms without quotes.
I would say macros is the way to go but I haven’t managed to make it work.
Does anybody know how? Thank you
I’m curious as to ‘why’ as well, the only ways to make atoms is a remote message from the mesh, compiling a module with the atom, or String.to_atom or its kin as far as I recall?
Sure.
I’m correcting the documentation, which have changed for OTP 20 onwards
diff --git a/lib/elixir/lib/list.ex b/lib/elixir/lib/list.ex
index 7c2678890..a0a12ecab 100644
--- a/lib/elixir/lib/list.ex
+++ b/lib/elixir/lib/list.ex
@@ -748,15 +748,19 @@ defmodule List do
@doc """
Converts a charlist to an atom.
- Currently Elixir does not support conversions from charlists
- which contains Unicode codepoints greater than 0xFF.
+ As of Erlang/OTP 20, Elixir supports conversions from charlists which contains
+ any Unicode codepoint. Earlier versions did not support convertions from
+ charlists which contains Unicode codepoints greater than 0xFF.
and the “Syntax Reference”, Which I’m trying to go thoroughly through, particularly the first codepoint of an atom, without using quotes. The page states states:
Atoms
Atoms in Elixir start with a colon (:) which must be followed by a non-combining Unicode character or underscore. The atom may continue using a sequence of Unicode characters, including letters, numbers, underscore, and @. Atoms may end in ! or ?. See Unicode Syntax for a formal specification.
All operators in Elixir are also valid atoms. Valid examples are :foo, :FOO, :foo_42, :foo@bar and :++. Invalid examples are :@foo (@ is not allowed at start), :123 (numbers are not allowed at start) and :(*) (not a valid operator).
If the colon is followed by a double- or single-quote, the atom can be made of any character, such as :"++olá++".