Comments (1)
The docs say
If macros would get informed about whether they are defined within another function
The difficulty I see with this is that macros are expanded prior to the builtin code lowering passes. But knowing "whether they are defined within another function" is, by definition part of the closure detection and lowering pass.
So requiring knowledge of this from within a macro seems close to a circular dependency.
It might be valid to intersperse user-defined macro expansion with other code desugaring steps in a hierarchical way. Particularly, this seems valid if we assume macros are pure functions, and only intersperse macro expansion with other strictly hierarchical code desugaring steps.
In that case I think it would be consistent to provide information from the lexical environment to macros. For example, which top level function they belong to. In fact we already do this by providing the __module__
parameter to macro expansion.
However, it's relatively easy to arrange for the __module__
to exist prior to macro expansion. Making sure a function exists in eval()'d
form is more problematic — it more comprehensively breaks the separation between lowering (a symbolic transformation) and evaluation (with all the side effects that eval
has on the Julia runtime).
A saner alternative could be to provide only symbolic information about lexical environment to macro expansion. So for example, macros could potentially know which name of top level function they are being expanded within, but not have access to the eval
'd function object itself.
IIUC, Jeff previously (a couple of years ago in a discussion) expressed some dissatisfaction with how macro expansion redoes some work which is later done in lowering. So there may be appetite to revisit how some of this works.
As a summary, I think
- This is an interesting feature request which probably could be implemented
- It requires a fairly major change to internals of how lowering and macro expansion interacts with lowering
- However, such an internal change might be needed anyway to fix some other related implementation issues and should be non-breaking
from juliasyntax.jl.
Related Issues (20)
- Syntax coloring for doctests HOT 2
- Error message could suggest comma instead of `)` HOT 1
- Parser fails when encountering `let` block inside incorrectly-terminated `let` block HOT 1
- poor handling of incomplete as a ParseError HOT 1
- recursion causes stackoverflow and crash HOT 10
- Unexpected `ParseError` with `import Makie: (..)` HOT 1
- Potential regression in JuliaSyntax parser failure error message HOT 3
- `i++` could use a better error message HOT 9
- eliminate dependency on Base.is_id_char and julia-specific utf8proc HOT 2
- Bug in tokenizer for certain floating point identifier syntax HOT 4
- Failures found using fuzz testing HOT 2
- `@m(x a=[b for c in d])` crashes parser HOT 2
- `import as if` HOT 3
- `BoundsError` when parsing expression with unbalanced parenthesis HOT 1
- Parser fails upon encountering `x = i m.:(var"t")` HOT 1
- Parser fails upon encountering `x.args[1] for x in kw` HOT 1
- `"a +\n\n>:"` and related expressions with `>:` parse incorrectly
- `A where {T} == Z` parsing inconsistency with flisp parser HOT 1
- Difference in parsing `x.[y]` to `Expr` HOT 2
- Error message implies missing parenthesis, but the issue is a missing argument HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from juliasyntax.jl.