Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pangoraw/hygienic.jl
:soap: Hygiene at macro definition time
https://github.com/pangoraw/hygienic.jl
Last synced: 26 days ago
JSON representation
:soap: Hygiene at macro definition time
- Host: GitHub
- URL: https://github.com/pangoraw/hygienic.jl
- Owner: Pangoraw
- License: mit
- Created: 2022-03-11T22:05:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-03-12T17:48:37.000Z (over 2 years ago)
- Last Synced: 2024-10-09T07:12:15.870Z (30 days ago)
- Language: Julia
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hygienic.jl
A small package to avoid the problem of leaking variables between macros. Consider the following macro `@b` that calls another macro `@a`. Since they both set a value to `x` and they share the same expansion context, the variable `##x#000` will be shared in both macros even though the name is gensymed. This can lead to confusing bugs when working with stacked macros.
```julia
macro a()
quote
x = :a
end
endmacro b()
quote
x = :b
@a()
x # <- x is :a here
end
end
```## Solutions
Hygienic exports a single macro `@hygienize` to do the hygiene at the macro definition step instead of at macro call time. This makes sure that no variable will leak to another macro.
```julia
macro a()
@hygienize quote
x = :a
end
end
```