There aren’t a ton of Sigils in Elixir and I certainly don’t think they make or break the language. The language provides sigils for character lists, regular expressions, strings, word lists, and date times.
The most common that I encounter are probably the word list and regular expression sigils. A brief example would be:
~w(foo #{:bar} baz) # => ["foo", "bar", "baz"]
~w(--source tests/test_sigils) # => ["--source", "tests/test_sigils"]
Sigils in Elixir also support the concept of “modifiers” allowing you to do something like:
~w(foo bar baz)a # => [:foo, :bar, :baz]
The “a” modifier tells the sigil that the list of words are intended to be atoms.
However, the language also provides the ability to create custom sigils for something like:
`~p(users bryansray delete) # => “users/bryansray/delete”
This would be a simple “path” sigil would take advantage of Path.join
in order to accomplish it’s goal.
Phoenix also has an ~e
and ~E
sigil(s) that are used for safe HTML escaping
As I mentioned, I don’t really know if sigil’s fully make sense in Crystal. They were just a very interesting language feature that I enjoy in Elixir. And I wanted to make sure there wasn’t something obvious that I was missing in Crystal.