Skip to content

Commit fe2e4a1

Browse files
author
José Valim
committed
Move from // to \\
1 parent 50e4793 commit fe2e4a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+246
-236
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
* Deprecations
1717
* [Kernel] `binary_to_term/1`, `binary_to_term/2`, `term_to_binary/1` and `term_to_binary/2` are deprecated in favor of their counterparts in the `:erlang` module
18+
* [Kernel] `//` for default arguments is deprecated in favor of `\\`. This is a soft deprecation, no warnings will be emitted for it in this release
1819
* [Record] Deprecate `to_keywords`, `getter` and `list getter` functionalities in `defrecordp`
1920

2021
* Backwards incompatible changes

lib/eex/lib/eex.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ defmodule EEx do
105105
Sample.sample(1, 2) #=> "3"
106106
107107
"""
108-
defmacro function_from_string(kind, name, source, args // [], options // []) do
108+
defmacro function_from_string(kind, name, source, args \\ [], options \\ []) do
109109
quote bind_quoted: binding do
110110
info = Keyword.merge [file: __ENV__.file, line: __ENV__.line], options
111111
args = Enum.map args, fn arg -> { arg, [line: info[:line]], nil } end
@@ -141,7 +141,7 @@ defmodule EEx do
141141
Sample.sample(1, 2) #=> "3"
142142
143143
"""
144-
defmacro function_from_file(kind, name, file, args // [], options // []) do
144+
defmacro function_from_file(kind, name, file, args \\ [], options \\ []) do
145145
quote bind_quoted: binding do
146146
info = Keyword.merge options, [file: file, line: 1]
147147
args = Enum.map args, fn arg -> { arg, [line: 1], nil } end
@@ -159,15 +159,15 @@ defmodule EEx do
159159
Get a string `source` and generate a quoted expression
160160
that can be evaluated by Elixir or compiled to a function.
161161
"""
162-
def compile_string(source, options // []) do
162+
def compile_string(source, options \\ []) do
163163
EEx.Compiler.compile(source, options)
164164
end
165165

166166
@doc """
167167
Get a `filename` and generate a quoted expression
168168
that can be evaluated by Elixir or compiled to a function.
169169
"""
170-
def compile_file(filename, options // []) do
170+
def compile_file(filename, options \\ []) do
171171
options = Keyword.merge options, [file: filename, line: 1]
172172
compile_string(File.read!(filename), options)
173173
end
@@ -181,7 +181,7 @@ defmodule EEx do
181181
#=> "foo baz"
182182

183183
"""
184-
def eval_string(source, bindings // [], options // []) do
184+
def eval_string(source, bindings \\ [], options \\ []) do
185185
compiled = compile_string(source, options)
186186
do_eval(compiled, bindings, options)
187187
end
@@ -199,7 +199,7 @@ defmodule EEx do
199199
#=> "foo baz"
200200
201201
"""
202-
def eval_file(filename, bindings // [], options // []) do
202+
def eval_file(filename, bindings \\ [], options \\ []) do
203203
options = Keyword.put options, :file, filename
204204
compiled = compile_file(filename, options)
205205
do_eval(compiled, bindings, options)

lib/eex/test/eex/smart_engine_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ defmodule EEx.SmartEngineTest do
2020
assert_eval "1\n2\n3\n", "<%= lc x inlist [1, 2, 3] do %><%= x %>\n<% end %>"
2121
end
2222

23-
defp assert_eval(expected, actual, binding // []) do
23+
defp assert_eval(expected, actual, binding \\ []) do
2424
result = EEx.eval_string(actual, binding, file: __ENV__.file)
2525
assert result == expected
2626
end

lib/elixir/lib/application/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule Application.Behaviour do
7575
# Application.Behaviour.start(:my_app)
7676
#
7777
@doc false
78-
def start(app, type // :temporary) do
78+
def start(app, type \\ :temporary) do
7979
case :application.start(app, type) do
8080
{ :error, { :not_started, dep } } ->
8181
case start(dep) do

lib/elixir/lib/behaviour.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ defmodule Behaviour do
122122
raise ArgumentError, message: "default arguments // not supported in defcallback/defmacrocallback"
123123
end
124124

125+
defp ensure_not_default({ :\\, _, [_, _] }) do
126+
raise ArgumentError, message: "default arguments \\\\ not supported in defcallback/defmacrocallback"
127+
end
128+
125129
defp ensure_not_default(_), do: :ok
126130

127131
@doc false

lib/elixir/lib/code.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ defmodule Code do
115115
{3, [a: 1, b: 2]}
116116
117117
"""
118-
def eval_string(string, binding // [], opts // [])
118+
def eval_string(string, binding \\ [], opts \\ [])
119119

120120
def eval_string(string, binding, Macro.Env[] = env) do
121121
do_eval_string(string, binding, env.to_keywords)
@@ -150,7 +150,7 @@ defmodule Code do
150150
{3, [a: 1, b: 2]}
151151
152152
"""
153-
def eval_quoted(quoted, binding // [], opts // [])
153+
def eval_quoted(quoted, binding \\ [], opts \\ [])
154154

155155
def eval_quoted(quoted, binding, Macro.Env[] = env) do
156156
do_eval_quoted(quoted, binding, env.to_keywords)
@@ -225,7 +225,7 @@ defmodule Code do
225225
`Macro.to_string/2`, which converts a quoted form to a string/binary
226226
representation.
227227
"""
228-
def string_to_quoted(string, opts // []) when is_list(opts) do
228+
def string_to_quoted(string, opts \\ []) when is_list(opts) do
229229
file = Keyword.get opts, :file, "nofile"
230230
line = Keyword.get opts, :line, 1
231231
res = :elixir.string_to_quoted(to_char_list(string), line, file, opts)
@@ -246,7 +246,7 @@ defmodule Code do
246246
247247
Check `string_to_quoted/2` for options information.
248248
"""
249-
def string_to_quoted!(string, opts // []) when is_list(opts) do
249+
def string_to_quoted!(string, opts \\ []) when is_list(opts) do
250250
file = Keyword.get opts, :file, "nofile"
251251
line = Keyword.get opts, :line, 1
252252
:elixir.string_to_quoted!(to_char_list(string), line, file, opts)
@@ -266,7 +266,7 @@ defmodule Code do
266266
a given file, the given file will be loaded N times. Check
267267
`require_file/2` if you don't want a file to be loaded concurrently.
268268
"""
269-
def load_file(file, relative_to // nil) when is_binary(file) do
269+
def load_file(file, relative_to \\ nil) when is_binary(file) do
270270
file = find_file(file, relative_to)
271271
:elixir_code_server.call { :acquire, file }
272272
loaded = :elixir_compiler.file file
@@ -289,7 +289,7 @@ defmodule Code do
289289
290290
Check `load_file/2` if you want a file to be loaded concurrently.
291291
"""
292-
def require_file(file, relative_to // nil) when is_binary(file) do
292+
def require_file(file, relative_to \\ nil) when is_binary(file) do
293293
file = find_file(file, relative_to)
294294

295295
case :elixir_code_server.call({ :acquire, file }) do
@@ -346,7 +346,7 @@ defmodule Code do
346346
347347
For compiling many files at once, check `Kernel.ParallelCompiler.files/2`.
348348
"""
349-
def compile_string(string, file // "nofile") when is_binary(file) do
349+
def compile_string(string, file \\ "nofile") when is_binary(file) do
350350
:elixir_compiler.string to_char_list(string), file
351351
end
352352

@@ -357,7 +357,7 @@ defmodule Code do
357357
the first element is the module name and the second one is its
358358
binary.
359359
"""
360-
def compile_quoted(quoted, file // "nofile") when is_binary(file) do
360+
def compile_quoted(quoted, file \\ "nofile") when is_binary(file) do
361361
:elixir_compiler.quoted quoted, file
362362
end
363363

lib/elixir/lib/dict.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ defmodule Dict do
163163
3
164164
"""
165165
@spec get(t, key, value) :: value
166-
def get(dict, key, default // nil) do
166+
def get(dict, key, default \\ nil) do
167167
target(dict).get(dict, key, default)
168168
end
169169

@@ -286,7 +286,7 @@ defmodule Dict do
286286
287287
"""
288288
@spec merge(t, t, (key, value, value -> value)) :: t
289-
def merge(dict1, dict2, fun // fn(_k, _v1, v2) -> v2 end) do
289+
def merge(dict1, dict2, fun \\ fn(_k, _v1, v2) -> v2 end) do
290290
target1 = target(dict1)
291291
target2 = target(dict2)
292292

@@ -322,7 +322,7 @@ defmodule Dict do
322322
323323
"""
324324
@spec pop(t, key, value) :: {value, t}
325-
def pop(dict, key, default // nil) do
325+
def pop(dict, key, default \\ nil) do
326326
target(dict).pop(dict, key, default)
327327
end
328328

lib/elixir/lib/dict/behaviour.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ defmodule Dict.Behaviour do
5050
Note you can also test your custom module via `Dict`'s doctests:
5151
5252
defmodule MyDict do
53-
def new(keywords // []) do
53+
def new(keywords \\ []) do
5454
...
5555
end
5656
end
@@ -66,7 +66,7 @@ defmodule Dict.Behaviour do
6666
quote do
6767
@behaviour Dict
6868

69-
def get(dict, key, default // nil) do
69+
def get(dict, key, default \\ nil) do
7070
case fetch(dict, key) do
7171
{ :ok, value } -> value
7272
:error -> default
@@ -133,7 +133,7 @@ defmodule Dict.Behaviour do
133133
end
134134
end
135135

136-
def merge(dict1, dict2, fun // fn(_k, _v1, v2) -> v2 end) do
136+
def merge(dict1, dict2, fun \\ fn(_k, _v1, v2) -> v2 end) do
137137
reduce(dict1, { :cont, dict2 }, fn { k, v1 }, acc ->
138138
{ :cont, update(acc, k, v1, &fun.(k, v1, &1)) }
139139
end) |> elem(1)

lib/elixir/lib/enum.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ defmodule Enum do
209209
@spec all?(t) :: boolean
210210
@spec all?(t, (element -> as_boolean(term))) :: boolean
211211

212-
def all?(collection, fun // fn(x) -> x end)
212+
def all?(collection, fun \\ fn(x) -> x end)
213213

214214
def all?(collection, fun) when is_list(collection) do
215215
do_all?(collection, fun)
@@ -245,7 +245,7 @@ defmodule Enum do
245245
@spec any?(t) :: boolean
246246
@spec any?(t, (element -> as_boolean(term))) :: boolean
247247

248-
def any?(collection, fun // fn(x) -> x end)
248+
def any?(collection, fun \\ fn(x) -> x end)
249249

250250
def any?(collection, fun) when is_list(collection) do
251251
do_any?(collection, fun)
@@ -275,7 +275,7 @@ defmodule Enum do
275275
"""
276276
@spec at(t, integer) :: element | nil
277277
@spec at(t, integer, default) :: element | default
278-
def at(collection, n, default // nil) do
278+
def at(collection, n, default \\ nil) do
279279
case fetch(collection, n) do
280280
{ :ok, h } -> h
281281
:error -> default
@@ -315,7 +315,7 @@ defmodule Enum do
315315
"""
316316
@spec chunk(t, non_neg_integer, non_neg_integer) :: [list]
317317
@spec chunk(t, non_neg_integer, non_neg_integer, t | nil) :: [list]
318-
def chunk(coll, n, step, pad // nil) when n > 0 and step > 0 do
318+
def chunk(coll, n, step, pad \\ nil) when n > 0 and step > 0 do
319319
limit = :erlang.max(n, step)
320320

321321
{ _, { acc, { buffer, i } } } =
@@ -671,7 +671,7 @@ defmodule Enum do
671671
"""
672672
@spec find(t, (element -> any)) :: element | nil
673673
@spec find(t, default, (element -> any)) :: element | default
674-
def find(collection, ifnone // nil, fun)
674+
def find(collection, ifnone \\ nil, fun)
675675

676676
def find(collection, ifnone, fun) when is_list(collection) do
677677
do_find(collection, ifnone, fun)
@@ -698,7 +698,7 @@ defmodule Enum do
698698
"""
699699
@spec find_value(t, (element -> any)) :: any | :nil
700700
@spec find_value(t, any, (element -> any)) :: any | :nil
701-
def find_value(collection, ifnone // nil, fun)
701+
def find_value(collection, ifnone \\ nil, fun)
702702

703703
def find_value(collection, ifnone, fun) when is_list(collection) do
704704
do_find_value(collection, ifnone, fun)
@@ -846,7 +846,7 @@ defmodule Enum do
846846
"""
847847
@spec join(t) :: String.t
848848
@spec join(t, String.t) :: String.t
849-
def join(collection, joiner // "")
849+
def join(collection, joiner \\ "")
850850

851851
def join(collection, joiner) when is_binary(joiner) do
852852
reduce(collection, "", fn
@@ -899,7 +899,7 @@ defmodule Enum do
899899
"""
900900
@spec map_join(t, (element -> any)) :: String.t
901901
@spec map_join(t, String.t, (element -> any)) :: String.t
902-
def map_join(collection, joiner // "", mapper)
902+
def map_join(collection, joiner \\ "", mapper)
903903

904904
def map_join(collection, joiner, mapper) when is_binary(joiner) do
905905
reduce(collection, "", fn
@@ -1585,7 +1585,7 @@ defmodule Enum do
15851585
"""
15861586
@spec uniq(t) :: list
15871587
@spec uniq(t, (element -> term)) :: list
1588-
def uniq(collection, fun // fn x -> x end)
1588+
def uniq(collection, fun \\ fn x -> x end)
15891589

15901590
def uniq(collection, fun) when is_list(collection) do
15911591
do_uniq(collection, [], fun)

lib/elixir/lib/exception.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ defmodule Exception do
255255
calculates a new stacktrace based on the caller and formats it. As
256256
a consequence, the value of `System.stacktrace` is changed.
257257
"""
258-
def format_stacktrace(trace // nil) do
258+
def format_stacktrace(trace \\ nil) do
259259
trace = trace || try do
260260
throw(:stacktrace)
261261
catch
@@ -278,7 +278,7 @@ defmodule Exception do
278278
Notice that due to tail call optimization, the stacktrace
279279
may not report the direct caller of the function.
280280
"""
281-
def format_caller(trace // nil) do
281+
def format_caller(trace \\ nil) do
282282
trace = trace || try do
283283
throw(:stacktrace)
284284
catch

0 commit comments

Comments
 (0)