Skip to content

Commit f9a7552

Browse files
Fix incorrect examples and typos in guides (#15620)
The guide pages under lib/elixir/pages are not doctests, so some example outputs drifted from what current Elixir prints. I re-ran each example on main (1.21.0-dev, OTP 29) with a clean IEx and updated the blocks to match the actual output. Also fixes two typos. Map ordering examples were left untouched since small-map print order is not guaranteed across OTP versions. Signed-off-by: Patric Vinicios <psdev7@gmail.com>
1 parent f2ad598 commit f9a7552

6 files changed

Lines changed: 12 additions & 11 deletions

File tree

lib/elixir/pages/anti-patterns/code-anti-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ iex> MyRequestHandler.parse(%{"status" => "status_not_seen_anywhere", "message"
197197

198198
By explicitly listing all supported statuses, you guarantee that only a limited number of conversions may happen, and that all expected atoms already exist within the system.
199199

200-
An alternative is to use pattern matching and explicitly convert each string to its respective atom. This is useful when you need additional logic on differnt branches:
200+
An alternative is to use pattern matching and explicitly convert each string to its respective atom. This is useful when you need additional logic on different branches:
201201

202202
```elixir
203203
defmodule MyRequestHandler do

lib/elixir/pages/anti-patterns/process-anti-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ iex> C.update(agent)
144144

145145
# state of shared information
146146
iex> D.get(agent)
147-
[:atom_value, %{a: 123}]
147+
[:atom_value | %{a: 123}]
148148
```
149149

150150
For a `GenServer` and other behaviours, this anti-pattern will manifest when scattering calls to `GenServer.call/3` and `GenServer.cast/2` throughout multiple modules, instead of encapsulating all the interaction with the `GenServer` in a single place.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ As hinted at the beginning of this chapter, sigils in Elixir are extensible. In
214214

215215
```elixir
216216
iex> sigil_r(<<"foo">>, [?i])
217-
~r"foo"i
217+
~r/foo/i
218218
```
219219

220220
We can access the documentation for the `~r` sigil via `sigil_r`:

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ iex> require Unless
4646
iex> Unless.macro_unless(true, do: IO.puts("this should never be printed"))
4747
nil
4848
iex> Unless.fun_unless(true, do: IO.puts("this should never be printed"))
49-
"this should never be printed"
49+
this should never be printed
5050
nil
5151
```
5252

@@ -81,7 +81,7 @@ We can actually verify that this is the case by using `Macro.expand_once/2`:
8181
iex> expr = quote do: Unless.macro_unless(true, do: IO.puts("this should never be printed"))
8282
iex> res = Macro.expand_once(expr, __ENV__)
8383
iex> IO.puts(Macro.to_string(res))
84-
if(!true) do
84+
if !true do
8585
IO.puts("this should never be printed")
8686
end
8787
:ok
@@ -214,11 +214,11 @@ nil
214214
iex> __ENV__.file
215215
"iex"
216216
iex> __ENV__.requires
217-
[IEx.Helpers, Kernel, Kernel.Typespec]
217+
[Application, IEx.Helpers, Kernel]
218218
iex> require Integer
219-
nil
219+
Integer
220220
iex> __ENV__.requires
221-
[IEx.Helpers, Integer, Kernel, Kernel.Typespec]
221+
[Application, IEx.Helpers, Integer, Kernel]
222222
```
223223

224224
Many of the functions in the `Macro` module expect a `Macro.Env` environment. You can read more about these functions in `Macro` and learn more about the compilation environment in the `Macro.Env`.

lib/elixir/pages/meta-programming/quote-and-unquote.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Operators are also represented as such tuples:
2828

2929
```elixir
3030
iex> quote do: 1 + 2
31-
{:+, [context: Elixir, import: Kernel], [1, 2]}
31+
{:+, [context: Elixir, imports: [{1, Kernel}, {2, Kernel}]], [1, 2]}
3232
```
3333

3434
Even a map is represented as a call to `%{}`:
@@ -49,7 +49,8 @@ When quoting more complex expressions, we can see that the code is represented i
4949

5050
```elixir
5151
iex> quote do: sum(1, 2 + 3, 4)
52-
{:sum, [], [1, {:+, [context: Elixir, import: Kernel], [2, 3]}, 4]}
52+
{:sum, [],
53+
[1, {:+, [context: Elixir, imports: [{1, Kernel}, {2, Kernel}]], [2, 3]}, 4]}
5354
```
5455

5556
Sometimes, when working with quoted expressions, it may be useful to get the textual code representation back. This can be done with `Macro.to_string/1`:

lib/elixir/pages/references/gradual-set-theoretic-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ user = find_user_by_id(42)
266266
%User{user | name: "John Doe"}
267267
```
268268

269-
Even though it is guaranteed at runtime that user is always a `User` struct. If the type system cannot prove it, it will emit a typing violation. This is how stuct updates work by design. In such cases, you can address it by matching on the struct when the user variable is defined:
269+
Even though it is guaranteed at runtime that user is always a `User` struct. If the type system cannot prove it, it will emit a typing violation. This is how struct updates work by design. In such cases, you can address it by matching on the struct when the user variable is defined:
270270

271271
```elixir
272272
%User{} = user = find_user_by_id(42)

0 commit comments

Comments
 (0)