Skip to content

Commit 84a0985

Browse files
author
José Valim
committed
Deprecate quote binding: in favor of quote bind_quoted:
1 parent 73b9ac7 commit 84a0985

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [Enum] Receiving the index of iteration in `Enum.map/2` and `Enum.each/2` is deprecated in favor of `Stream.with_index/1`
2626
* [File] `File.iterator/1` and `File.biniterator/1` are deprecated in favor of `IO.stream/1` and `IO.binstream/1`
2727
* [File] `File.iterator!/2` and `File.biniterator!/2` are deprecated in favor of `File.stream!/2` and `File.binstream!/2`
28+
* [Kernel] Deprecate recently added `quote binding: ...` in favor of the clearer `quote bind_quoted: ...`
2829
* [Record] `Record.__index__/2` deprecated in favor of `Record.__record__(:index, key)`
2930

3031
* backwards incompatible changes

lib/elixir/lib/io/ansi.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule IO.ANSI.Sequence do
22
@moduledoc false
33

44
defmacro defsequence(name, code) do
5-
quote binding: [name: name, code: code] do
5+
quote bind_quoted: [name: name, code: code] do
66
def unquote(name)() do
77
"\e[#{unquote(code)}m"
88
end

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,13 @@ defmodule Kernel.SpecialForms do
689689
690690
One solution for this problem is to disable unquoting in the
691691
macro, however, doing that would make it impossible to inject
692-
`kv` representation into the tree. That's when the `:binding`
693-
option comes to the rescue. By using `:binding`, we can
692+
`kv` representation into the tree. That's when the `:bind_quoted`
693+
option comes to the rescue. By using `:bind_quoted`, we can
694694
automatically disable unquoting while still injecting the
695695
desired variables into the tree:
696696
697697
defmacro defkv(kv) do
698-
quote binding: [kv: kv] do
698+
quote bind_quoted: [kv: kv] do
699699
Enum.each kv, fn { k, v } ->
700700
def unquote(k)(), do: unquote(v)
701701
end

lib/elixir/src/elixir_translator.erl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ translate_each({ quote, Meta, [KV, Do] }, S) when is_list(Do) ->
205205
false -> syntax_error(Meta, S#elixir_scope.file, "invalid args for quote")
206206
end,
207207

208-
ValidOpts = [hygiene, context, var_context, location, line, file, unquote, binding],
208+
ValidOpts = [hygiene, context, var_context, location, line, file, unquote, binding, bind_quoted],
209209
{ TKV, ST } = translate_opts(Meta, quote, ValidOpts, KV, S),
210210

211211
Hygiene = case lists:keyfind(hygiene, 1, TKV) of
@@ -261,8 +261,14 @@ translate_each({ quote, Meta, [KV, Do] }, S) when is_list(Do) ->
261261
end,
262262

263263
{ Binding, DefaultUnquote } = case lists:keyfind(binding, 1, TKV) of
264-
{ binding, B } when is_list(B) -> { B, false };
265-
false -> { nil, true }
264+
{ binding, B } when is_list(B) ->
265+
elixir_errors:deprecation(Meta, S#elixir_scope.file, ":binding in quote is deprecated in favor of :bind_quoted"),
266+
{ B, false };
267+
false ->
268+
case lists:keyfind(bind_quoted, 1, TKV) of
269+
{ bind_quoted, BQ } -> { BQ, false };
270+
false -> { nil, true }
271+
end
266272
end,
267273

268274
Unquote = case lists:keyfind(unquote, 1, TKV) of

lib/elixir/test/elixir/kernel/quote_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ defmodule Kernel.QuoteTest do
158158
assert quote(dynamic_opts, do: bar(1, 2, 3)) == { :bar, [line: 3], [1, 2, 3] }
159159
end
160160

161-
test :binding do
162-
assert quote(binding: [foo: 1 + 2], do: foo) == { :__block__, [], [
161+
test :bind_quoted do
162+
assert quote(bind_quoted: [foo: 1 + 2], do: foo) == { :__block__, [], [
163163
{ :=, [], [{ :foo, [], Kernel.QuoteTest }, 3] },
164164
{ :foo, [], Kernel.QuoteTest }
165165
] }

lib/ex_unit/lib/ex_unit/case.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ defmodule ExUnit.Case do
8484
var = Macro.escape(var)
8585
contents = Macro.escape(contents, unquote: true)
8686

87-
quote binding: binding do
87+
quote bind_quoted: binding do
8888
message = if is_binary(message) do
8989
:"test #{message}"
9090
else

0 commit comments

Comments
 (0)