Skip to content

Commit 39d1ecb

Browse files
authored
Various small improvements in guides and docs (#13887)
1 parent 63e9caf commit 39d1ecb

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

lib/elixir/lib/code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ defmodule Code do
185185
186186
defmodule MyTracer do
187187
def trace({:remote_function, _meta, module, name, arity}, env) do
188-
IO.puts "#{env.file}:#{env.line} #{inspect(module)}.#{name}/#{arity}"
188+
IO.puts("#{env.file}:#{env.line} #{inspect(module)}.#{name}/#{arity}")
189189
:ok
190190
end
191191

lib/elixir/lib/task.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,14 +842,14 @@ defmodule Task do
842842
Process.demonitor(ref, [:flush])
843843
844844
{url, state} = pop_in(state.tasks[ref])
845-
IO.puts "Got #{inspect(result)} for URL #{inspect url}"
845+
IO.puts("Got #{inspect(result)} for URL #{inspect url}")
846846
{:noreply, state}
847847
end
848848
849849
# If the task fails...
850850
def handle_info({:DOWN, ref, _, _, reason}, state) do
851851
{url, state} = pop_in(state.tasks[ref])
852-
IO.puts "URL #{inspect url} failed with reason #{inspect(reason)}"
852+
IO.puts("URL #{inspect url} failed with reason #{inspect(reason)}")
853853
{:noreply, state}
854854
end
855855
end

lib/elixir/lib/task/supervisor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ defmodule Task.Supervisor do
498498
Starts a task as a child of the given `supervisor`.
499499
500500
Task.Supervisor.start_child(MyTaskSupervisor, fn ->
501-
IO.puts "I am running in a task"
501+
IO.puts("I am running in a task")
502502
end)
503503
504504
Note that the spawned process is not linked to the caller, but

lib/elixir/pages/getting-started/basic-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ iex> 1 == 2.0
322322
false
323323
```
324324
325-
However, you can use the strict comparison operator [`===`](`===/2`) and [`!==`](`!==/2`) if you want to distinguish between integers and floats (that's the only difference between these operators):
325+
However, you can use the strict comparison operator [`===`](`===/2`) and [`!==`](`!==/2`) if you want to distinguish between integers and floats:
326326
327327
```elixir
328328
iex> 1 === 1.0

lib/elixir/pages/getting-started/binaries-strings-and-charlists.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ iex> String.valid?(<<239, 191, 19>>)
184184
false
185185
```
186186

187-
The string concatenation operator `<>` is actually a binary concatenation operator:
187+
The string concatenation operator [`<>`](`<>/2`) is actually a binary concatenation operator:
188188

189189
```elixir
190190
iex> "a" <> "ha"
@@ -243,7 +243,7 @@ iex> [?h, ?e, ?l, ?l, ?o]
243243
~c"hello"
244244
```
245245

246-
The `~c` sigil (we'll cover sigils later in the ["Sigils"](sigils.md) chapter) indicates the fact that we are dealing with a charlist and not a regular string.
246+
The [`~c`](`Kernel.sigil_c/2`) sigil (we'll cover sigils later in the ["Sigils"](sigils.md) chapter) indicates the fact that we are dealing with a charlist and not a regular string.
247247

248248
Instead of containing bytes, a charlist contains integer code points. However, the list is only printed as a sigil if all code points are within the ASCII range:
249249

@@ -283,7 +283,7 @@ iex> to_string(1)
283283

284284
The functions above are polymorphic, in other words, they accept many shapes: not only do they convert charlists to strings (and vice-versa), they can also convert integers, atoms, and so on.
285285

286-
String (binary) concatenation uses the `<>` operator but charlists, being lists, use the list concatenation operator `++`:
286+
String (binary) concatenation uses the [`<>`](`<>/2`) operator but charlists, being lists, use the list concatenation operator [`++`](`++/2`):
287287

288288
```elixir
289289
iex> ~c"this " <> ~c"fails"

lib/elixir/pages/getting-started/debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ It is also very common to use `IO.inspect/2` with `binding/0`, which returns all
4646

4747
```elixir
4848
def some_fun(a, b, c) do
49-
IO.inspect binding()
49+
IO.inspect(binding())
5050
...
5151
end
5252
```

lib/elixir/pages/getting-started/module-attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ So far, we have seen how to define attributes, but how can we read them? Let's s
7373
```elixir
7474
defmodule MyServer do
7575
@service URI.parse("https://example.com")
76-
IO.inspect @service
76+
IO.inspect(@service)
7777
end
7878
```
7979

lib/elixir/pages/getting-started/modules-and-functions.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ defmodule Concat do
143143
end
144144
end
145145

146-
IO.puts Concat.join("Hello", "world") #=> Hello world
147-
IO.puts Concat.join("Hello", "world", "_") #=> Hello_world
146+
IO.puts(Concat.join("Hello", "world")) #=> Hello world
147+
IO.puts(Concat.join("Hello", "world", "_")) #=> Hello_world
148148
```
149149

150150
Any expression is allowed to serve as a default value, but it won't be evaluated during the function definition. Every time the function is invoked and any of its default values have to be used, the expression for that default value will be evaluated:
@@ -182,9 +182,9 @@ defmodule Concat do
182182
end
183183
end
184184

185-
IO.puts Concat.join("Hello", "world") #=> Hello world
186-
IO.puts Concat.join("Hello", "world", "_") #=> Hello_world
187-
IO.puts Concat.join("Hello") #=> Hello
185+
IO.puts(Concat.join("Hello", "world")) #=> Hello world
186+
IO.puts(Concat.join("Hello", "world", "_")) #=> Hello_world
187+
IO.puts(Concat.join("Hello")) #=> Hello
188188
```
189189

190190
When a variable is not used by a function or a clause, we add a leading underscore (`_`) to its name to signal this intent. This rule is also covered in our [Naming Conventions](../references/naming-conventions.md#underscore-_foo) document.
@@ -194,12 +194,12 @@ When using default values, one must be careful to avoid overlapping function def
194194
```elixir
195195
defmodule Concat do
196196
def join(a, b) do
197-
IO.puts "***First join"
197+
IO.puts("***First join")
198198
a <> b
199199
end
200200

201201
def join(a, b, sep \\ " ") do
202-
IO.puts "***Second join"
202+
IO.puts("***Second join")
203203
a <> sep <> b
204204
end
205205
end
@@ -219,13 +219,13 @@ $ iex concat.ex
219219
```
220220

221221
```elixir
222-
iex> Concat.join "Hello", "world"
222+
iex> Concat.join("Hello", "world")
223223
***First join
224224
"Helloworld"
225225
```
226226

227227
```elixir
228-
iex> Concat.join "Hello", "world", "_"
228+
iex> Concat.join("Hello", "world", "_")
229229
***Second join
230230
"Hello_world"
231231
```

lib/elixir/pages/getting-started/try-catch-and-rescue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ iex> defmodule RunAfter do
224224
...> def without_even_trying do
225225
...> raise "oops"
226226
...> after
227-
...> IO.puts "cleaning up!"
227+
...> IO.puts("cleaning up!")
228228
...> end
229229
...> end
230230
iex> RunAfter.without_even_trying

lib/elixir/pages/meta-programming/macros.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ and play with those definitions:
3838

3939
```elixir
4040
iex> require Unless
41-
iex> Unless.macro_unless(true, do: IO.puts "this should never be printed")
41+
iex> Unless.macro_unless(true, do: IO.puts("this should never be printed"))
4242
nil
43-
iex> Unless.fun_unless(true, do: IO.puts "this should never be printed")
43+
iex> Unless.fun_unless(true, do: IO.puts("this should never be printed"))
4444
"this should never be printed"
4545
nil
4646
```
@@ -50,7 +50,7 @@ In our *macro* implementation, the sentence was not printed, although it was pri
5050
In other words, when invoked as:
5151

5252
```elixir
53-
Unless.macro_unless(true, do: IO.puts "this should never be printed")
53+
Unless.macro_unless(true, do: IO.puts("this should never be printed"))
5454
```
5555

5656
Our `macro_unless` macro received the following:

lib/elixir/pages/mix-and-otp/distributed-tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Let's define a module named `Hello` in this shell:
3838

3939
```elixir
4040
iex> defmodule Hello do
41-
...> def world, do: IO.puts "hello world"
41+
...> def world, do: IO.puts("hello world")
4242
...> end
4343
```
4444

@@ -102,7 +102,7 @@ So far we have explored tasks that are started and run in isolation, without reg
102102

103103
```elixir
104104
task = Task.async(fn -> compute_something_expensive() end)
105-
res = compute_something_else()
105+
res = compute_something_else()
106106
res + Task.await(task)
107107
```
108108

0 commit comments

Comments
 (0)