Skip to content

Commit 19007be

Browse files
author
Tomas Pevny
committed
fixing
1 parent 36c94cc commit 19007be

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

docs/src/lectures/lecture_07/lecture.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,19 @@ CodeInfo(
7575
```
7676

7777
::: info Scope of eval
78-
`eval` function is always evaluated in the global scope of the `Module` in which it is called (note that there is that by default you operate in the `Main` module). Moreover, `eval` takes effect **after** the function has been has been executed. This can be demonstrated as
79-
```julia
80-
add1(x) = x + 1
81-
function redefine_add(x)
82-
eval(:(add1(x) = x - 1))
83-
add1(x)
84-
end
85-
julia> redefine_add(1)
86-
2
87-
88-
julia> redefine_add(1)
89-
0
90-
```
78+
`eval` function is always evaluated in the global scope of the `Module` in which it is called (note that there is that by default you operate in the `Main` module). Moreover, `eval` takes effect **after** the function has been has been executed. This can be demonstrated as
79+
```julia
80+
add1(x) = x + 1
81+
function redefine_add(x)
82+
eval(:(add1(x) = x - 1))
83+
add1(x)
84+
end
85+
julia> redefine_add(1)
86+
2
9187

88+
julia> redefine_add(1)
89+
0
90+
```
9291
:::
9392

9493
Macros are quite tricky to debug. Macro `@macroexpand` allows to observe the expansion of macros. Observe the effect as
@@ -103,7 +102,6 @@ function cosp2(x)
103102
@replace_sin 2 + sin(x)
104103
end
105104
```
106-
107105
First, Julia parses the code into the AST as
108106
```julia
109107
ex = Meta.parse("""

0 commit comments

Comments
 (0)