Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9bdc30

Browse files
committed
Minor fixes for meta section of getting_started guide
1 parent cbe43f1 commit e9bdc30

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

getting_started/meta/1.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ iex> Macro.to_string(quote do: 11 + unquote(number))
9898

9999
```iex
100100
iex> fun = :hello
101-
iex> Macro.to_string(quote do: unquote(hello)(:world))
101+
iex> Macro.to_string(quote do: unquote(fun)(:world))
102102
"hello(:world)"
103103
```
104104

@@ -107,15 +107,15 @@ In some cases, it may be necessary to inject many values inside a list. For exam
107107
```iex
108108
iex> inner = [3, 4, 5]
109109
iex> Macro.to_string(quote do: [1, 2, unquote(inner), 6])
110-
[1, 2, [3, 4, 5], 6]
110+
"[1, 2, [3, 4, 5], 6]"
111111
```
112112

113113
That's when `unquote_splicing` becomes handy:
114114

115115
```iex
116116
iex> inner = [3, 4, 5]
117117
iex> Macro.to_string(quote do: [1, 2, unquote_splicing(inner), 6])
118-
[1, 2, 3, 4, 5, 6]
118+
"[1, 2, 3, 4, 5, 6]"
119119
```
120120

121121
Unquoting is very useful when working with macros. When writing macros, developers are able to receive code chunks and inject them inside other code chunks, being able to transform code or write code that generates code during compilation.

getting_started/meta/2.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ iex> Unless.fun_unless true, IO.puts "this should never be printed"
4545
nil
4646
```
4747

48-
Note that in our macro implementation, the sentence was not printed, although it was printed in our function implementation. That's because the arguments to a function call are evaluated before calling the function. However macros do not evaluate the arguments, instead they receive the arguments as quoted expressions which are then transformed into other quoted expressions. In this case, we have rewriten our `unless` macro to become an `if` behind the scenes.
48+
Note that in our macro implementation, the sentence was not printed, although it was printed in our function implementation. That's because the arguments to a function call are evaluated before calling the function. However macros do not evaluate the arguments, instead they receive the arguments as quoted expressions which are then transformed into other quoted expressions. In this case, we have rewritten our `unless` macro to become an `if` behind the scenes.
4949

5050
In other words, when invoked as:
5151

@@ -239,10 +239,12 @@ iex> __ENV__.file
239239
iex> __ENV__.requires
240240
[IEx.Helpers, Kernel, Kernel.Typespec]
241241
iex> require Integer
242+
nil
243+
iex> __ENV__.requires
242244
[IEx.Helpers, Integer, Kernel, Kernel.Typespec]
243245
```
244246

245-
Many of the functions in the `Macro` module expect an environment. You can read more about them in [the docs for the `Macro` module](/docs/stable/Macro.html) and learn mor about the compilation environment with [`Macro.Env`](/docs/stable/Macro.Env.html).
247+
Many of the functions in the `Macro` module expect an environment. You can read more about them in [the docs for the `Macro` module](/docs/stable/Macro.html) and learn more about the compilation environment with [`Macro.Env`](/docs/stable/Macro.Env.html).
246248

247249
## 2.5 Private macros
248250

0 commit comments

Comments
 (0)