Comments (2)
I should mention that the forward declaration is only required if the recursive macro invocation isn't qualified. But remembering to qualify it yourself is no easier than a forward declaration. The defmacro machinery should be able to do it for you somehow.
Making defmacro a reader macro wouldn't help, because inner reader macros evaluate first when composed, and unlike compiler macros, are not recursive.
Making defmacro expand to the forward declaration and then the definition in a progn
doesn't work either, because read time has already passed at that point.
Some possible solutions:
Option 1: Make template symbol in the function position expand to something like (hissp.._macro_.qualify foo)
to postpone the decision about how to qualify it until compile time. When the qualify
macro expands, it can check the current macro namespace. No changes are required for the compiler. But this will complicate the output of templates even more, making them harder to read and manipulate programmatically. And it changes the compile time type from a string to a tuple (which is arguably no worse than quote
, but still). And I think defmacro would still have to expand into a forward declaration in a progn
. If someone wants to implement their own more capable defmacro, this is a requirement they might miss.
Option 2: Make the templates always qualify symbols in the invocation place as a macro, and then make the compiler itself fall back to evaluating it like a global if there's no macro with that name. This is already similar to how the compiler handles unqualified symbols: assume macro first, and then fall back to global. It would make sense to assume an unqualified symbol in a template would act the same way. I like this better, however, it is confusing to see an explicit _macro_
qualification in a template when you intended a global, or to see an explicit _macro_
identifier evaluate as a global. Seems like it could cause or hide bugs in user code, which is not nice. And it would add yet another logic path to the compiler and reader, when I'm trying to avoid any bloat.
Option 3: Make the templates qualify symbols in the invocation place in some third way, like xINVOKE_
or xAUTO_
or something, and make the compiler use the "macro first, then global"-fallback logic for those. This helps with most of the problems from option 2. It's a little extra magic, but it's more consistent magic.
from hissp.
duplicate of #55
from hissp.
Related Issues (20)
- Rethink reader macros HOT 2
- Write a debugger macro walkthrough.
- Rethink ->> HOT 7
- Rethink `!` and `#""` HOT 12
- Handle qualified names in `attach`
- Stricter left-to-right evaluation order HOT 2
- `deftype` should be able to take `kwds`
- one time donations problem, please try receive some crypto as donation, maybe nano cryptocurrency
- Rethink `if-else` HOT 12
- Consider inject literals in Lissp (raw symbols) HOT 3
- Gensysms aren't good enough HOT 4
- Build broke on Python 3.11
- Synexpand may be too sensitive HOT 1
- & doesn't factor well in synexpand HOT 7
- Consider making gensym counter a reader instance variable
- Add source links to macros.lissp HOT 1
- defonce defs twice?
- Rename `&&` and `||` to `ands` and `ors` HOT 1
- #241 broke synexpand
- Dill integration HOT 1
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 hissp.