Skip to content

Commit 93a4a0f

Browse files
Add doctest for unquote_splicing in block context (#14404)
1 parent 207f5aa commit 93a4a0f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,7 @@ defmodule Kernel do
33923392
Converts the argument to a string according to the
33933393
`String.Chars` protocol.
33943394
3395-
This is the function invoked when there is string interpolation.
3395+
This is invoked when there is string interpolation.
33963396
33973397
## Examples
33983398

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,18 @@ defmodule Kernel.SpecialForms do
13721372
...> end
13731373
{:sum, [], [1, 2, 3, 4, 5]}
13741374
1375+
Also can be used in block context, outside of function arguments.
1376+
Though, it is still required to be wrapped into parentheses.
1377+
1378+
iex> requires = for module <- [Integer, Logger] do
1379+
...> quote do
1380+
...> require unquote(module)
1381+
...> end
1382+
...> end
1383+
iex> block = quote do: (unquote_splicing(requires))
1384+
iex> Macro.to_string(block)
1385+
"require Integer\\nrequire Logger"
1386+
13751387
"""
13761388
defmacro unquote(:unquote_splicing)(expr), do: error!([expr])
13771389

0 commit comments

Comments
 (0)