Skip to content

Commit 3706929

Browse files
committed
Updating default argument operator
1 parent 70e06e6 commit 3706929

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

crash-course.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ sum "a", "b"
565565
In addition, Elixir allows for default values for arguments, whereas Erlang does not.
566566

567567
```elixir
568-
def mul_by(x, n // 2) do
568+
def mul_by(x, n \\ 2) do
569569
x * n
570570
end
571571

getting_started/3.markdown

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Named functions also support default arguments:
129129

130130
```elixir
131131
defmodule Concat do
132-
def join(a, b, sep // " ") do
132+
def join(a, b, sep \\ " ") do
133133
a <> sep <> b
134134
end
135135
end
@@ -142,7 +142,7 @@ Any expression is allowed to serve as a default value, but it won't be evaluated
142142

143143
```elixir
144144
defmodule DefaultTest do
145-
def dowork(x // IO.puts "hello") do
145+
def dowork(x \\ IO.puts "hello") do
146146
x
147147
end
148148
end
@@ -160,7 +160,7 @@ If a function with default values has multiple clauses, it is recommended to cre
160160

161161
```elixir
162162
defmodule Concat do
163-
def join(a, b // nil, sep // " ")
163+
def join(a, b \\ nil, sep \\ " ")
164164

165165
def join(a, b, _sep) when nil?(b) do
166166
a
@@ -185,7 +185,7 @@ defmodule Concat do
185185
a <> b
186186
end
187187

188-
def join(a, b, sep // " ") do
188+
def join(a, b, sep \\ " ") do
189189
IO.puts "***Second join"
190190
a <> sep <> b
191191
end

getting_started/6.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ As you can see, invoking `h()` prints the documentation of `IEx.Helpers`. From t
124124

125125
```iex
126126
iex> h(c/2)
127-
* def c(files, path // ".")
127+
* def c(files, path \\ ".")
128128
...
129129
:ok
130130
```

0 commit comments

Comments
 (0)