There are a number of special character sequences in Elixir, for example the pipeline operator |>
but now I want to discuss the ~something
options.
These are sigils. The magic is simple if you call ~x(“something”) then the compiler will translate this into a call to sigil_x
~r/foo/i
becomes sigil_r(<<"foo">>, 'i')
See https://elixir-lang.org/getting-started/sigils.html for more details.
This does mean that you can now write your own sigils.
Here are the built in sigils. If there is an uppercase/lowercase pair they work the same except the lowercase one escapes the content.
sigil_C/2 sigil_c/2 returns a charlist
sigil_D/2 Creates date types
sigil_N/2 Creates native datetime
sigil_R/2 sigil_r/2 Regular expressions
sigil_S/2 sigil_s/2 Creates strings from literals
sigil_T/2 Creates time types
sigil_U/2 Creates a UTC Datetime
sigil_W/2 sigil_w/2 Creates a list of words by splitting on whitespace