-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: (attr once) for macros to enable safe macro side-effects #200
Comments
Another idea is |
ChangCat: Scopes for example will have two different kinds of macros: One, that works on the S-Expressions directly, like traditional lisp, and one that works on a typed AST.
|
@porky11 I know of Scopes, and feel that its approach with two different syntax tree is weird, i.e. one is the written sexp, and the other is the underlying semantics. In traditional Lisps and Dale, there is only one kind of syntax tree. Having two different kinds of syntax tree seems to be an unwanted complication. I have tried to reach its author along with some other concerns, but unfortunately haven't got any reply yet. I think Dale's approach is fine. It's already not perfectly safe to do side effects in a macro in traditional Lisp languages, and Dale's |
Another idea is that, we forbid overloading the same symbol with both functions and macros, when we can't determine only by the number of arguments whether it's function or macro to dispatch. This way, operator-macros will still work, and an entire class of multiple evaluation of macros is eliminated. This idea can be combined with |
That also was my idea, that |
Closing this issue, since we now have a better idea in #201 to enable safe macro side effects, without any attribute annotation. |
In general, a macro may be evaluated more than once, for the following cases:
type-of
eval-expression
eval-macro-call
Therefore it's not safe in general for macros to have side effects. On the other hand, macro side-effects are useful, so I suggest that we introduce a new attribute
(attr once)
, for those macros which do have side-effects to be safely written. This attribute will guarantee the macro is evaluated at most once, by prohibiting evaluation in all the above listed cases.It's still possible for one appearance of macro in source code to be evaluated more than once:
The text was updated successfully, but these errors were encountered: