diff options
author | José Valim <jose.valim@dashbit.co> | 2023-05-07 00:35:21 +0200 |
---|---|---|
committer | José Valim <jose.valim@dashbit.co> | 2023-05-07 00:35:21 +0200 |
commit | f4a77c5794f598f0ec3e4bb3267131fdda6d8a65 (patch) | |
tree | 362871a8eb8c1287d520bcdfb302a781118febc0 | |
parent | 8c69850adf67e9efa0070102ec53f50191138e5e (diff) | |
download | elixir-f4a77c5794f598f0ec3e4bb3267131fdda6d8a65.tar.gz |
Improve sigils docs
-rw-r--r-- | lib/elixir/lib/macro.ex | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index b952ca4ce..175f29b98 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -90,20 +90,27 @@ defmodule Macro do ### Examples + As an example, let's define a sigil `~x` and sigil `~X` which + return its contents as a string. However, if the `r` modifier + is given, it reverses the string instead: + defmodule MySigils do defmacro sigil_x(term, [?r]) do quote do unquote(term) |> String.reverse() end end + defmacro sigil_x(term, _modifiers) do term end + defmacro sigil_X(term, [?r]) do quote do unquote(term) |> String.reverse() end end + defmacro sigil_X(term, _modifiers) do term end @@ -112,16 +119,16 @@ defmodule Macro do import MySigils ~x(with #{"inter" <> "polation"}) - #=>"with interpolation" + #=> "with interpolation" ~x(with #{"inter" <> "polation"})r - #=>"noitalopretni htiw" + #=> "noitalopretni htiw" ~X(without #{"interpolation"}) - #=>"without \#{"interpolation"}" + #=> "without \#{"interpolation"}" ~X(without #{"interpolation"})r - #=>"}\"noitalopretni\"{# tuohtiw" + #=> "}\"noitalopretni\"{# tuohtiw" """ |