Skip to content

Commit c3b89fe

Browse files
committed
added an example of exfiltrate macro, but I do not know, if it useful
1 parent 957ef5a commit c3b89fe

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs/src/lecture_07/lecture.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,43 @@ also notice that the escaping is only partial (running `@macroexpand @m2 @m1 1 +
393393

394394
<!-- Why are variables on right-hand side replaced by access to global variables? -->
395395
## Write @exfiltrate macro
396-
`Base.@locals`
396+
```julia
397+
module Exfiltrator
398+
399+
const environment = Dict{Symbol, Any}()
400+
401+
add_variable!(name::Symbol, value) = environment[name] = value
402+
403+
function add_variables!(d::Dict)
404+
for (k, v) in d
405+
add_variable!(k, v)
406+
end
407+
end
408+
409+
function reset!()
410+
foreach(k -> delete!(environment, k), keys(environment))
411+
end
412+
413+
macro exfiltrate()
414+
quote
415+
reset!()
416+
add_variables!(Base.@locals)
417+
end
418+
end
419+
420+
export @exfiltrate
421+
422+
end
423+
```
424+
425+
```julia
426+
let
427+
x,y,z = 1,"hello", (a = "1", b = "b")
428+
@exfiltrate
429+
end
430+
Exfiltrator.environment
431+
```
432+
397433

398434

399435
## Domain Specifis Languages (DSL)

0 commit comments

Comments
 (0)