Skip to content

Commit 3967021

Browse files
committed
Trying out a toc
1 parent 3437368 commit 3967021

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

README.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ examples. This README will serve as my notes, therefore you shouldn't take them
1111
value as the notes will make sense for me as I cherry pick a sentence or an analogy.
1212
Moreover, don't expect direct quotes, changing the sentences vocbulary helps me personally.
1313

14-
<details>
15-
<summary>
16-
### Chapter 1 - The language of macros
17-
</summary>
14+
### Contents
15+
16+
- [Chapter 1 - The Language of Macros](#heading)
17+
- [What are Macros?](#sub-heading)
18+
- [The Abstract Syntax Tree](#sub-heading-1)
19+
- [Trying It All Together](sub-heading-2)
20+
21+
### Chapter 1 - The Language of Macros
22+
23+
#### What are Macros?
1824

1925
- Macros are code that write code.
2026
- Elixir itself is made with macros, as a result you can extend the language itself
@@ -65,36 +71,38 @@ iex> quote do: div(10, 2)
6571
In most languages, we would have to parse a string expression into something digestible by our program. With Elixir, we can access
6672
the representation of expressions directly with macros."
6773

68-
[First macro - `math.exs`](math.exs)
69-
70-
<!-- <details>
71-
<summary> [First macro - `math.exs`](math.exs) </summary>
72-
```elixir
73-
defmodule Math do
74-
@moduledoc false
75-
76-
defmacro say({:+, _, [lhs, rhs]}) do
77-
quote do
78-
lhs = unquote(lhs)
79-
rhs = unquote(rhs)
80-
result = lhs + rhs
81-
IO.puts("#{lhs} plus #{rhs} is #{result}")
82-
result
83-
end
84-
end
74+
[First macro - `math.exs`](math.exs)
8575

86-
defmacro say({:*, _, [lhs, rhs]}) do
87-
quote do
88-
lhs = unquote(lhs)
89-
rhs = unquote(rhs)
90-
result = lhs * rhs
91-
IO.puts("#{lhs} times #{rhs} is #{result}")
92-
result
93-
end
76+
<details>
77+
<summary>math.exs</summary>
78+
79+
```elixir
80+
defmodule Math do
81+
@moduledoc false
82+
83+
defmacro say({:+, _, [lhs, rhs]}) do
84+
quote do
85+
lhs = unquote(lhs)
86+
rhs = unquote(rhs)
87+
result = lhs + rhs
88+
IO.puts("#{lhs} plus #{rhs} is #{result}")
89+
result
9490
end
91+
end
92+
93+
defmacro say({:*, _, [lhs, rhs]}) do
94+
quote do
95+
lhs = unquote(lhs)
96+
rhs = unquote(rhs)
97+
result = lhs * rhs
98+
IO.puts("#{lhs} times #{rhs} is #{result}")
99+
result
95100
end
96-
```
97-
</details> -->
101+
end
102+
end
103+
```
104+
105+
</details>
98106

99107
Note when you use this in iex you need to first `c "math.exs"` then `require Math` but i've included it in [.iex.exs](.iex.exs) to save time.
100108
Automagically adding these when you open iex with `iex math.exs`.
@@ -140,5 +148,3 @@ Yes that's correct because we are dealing with ASTs not the data it represents;
140148
Much like interpolation from Ecto and the difference between `"Hello world"` and `"Hello #{world}`.
141149

142150
Back to the `math.exs`example.
143-
144-
</details>

0 commit comments

Comments
 (0)