You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/lectures/lecture_07/lecture.md
+12-14Lines changed: 12 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,20 +75,19 @@ CodeInfo(
75
75
```
76
76
77
77
::: 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
+
functionredefine_add(x)
82
+
eval(:(add1(x) = x -1))
83
+
add1(x)
84
+
end
85
+
julia>redefine_add(1)
86
+
2
91
87
88
+
julia>redefine_add(1)
89
+
0
90
+
```
92
91
:::
93
92
94
93
Macros are quite tricky to debug. Macro `@macroexpand` allows to observe the expansion of macros. Observe the effect as
0 commit comments