3 ms·
What do you see as the most important differences (or, what are the main kinds of macros for which syntax-rules is inadequate)?
by rwallace 10y ago
What do you see as the most important differences (or, what are the main kinds of macros for which syntax-rules is inadequate)?
- qwertyuiop924 10y agoSyntax-rules has difficulty in any context where referential opacity or the introduction of bindings is desired. This means anaphoric macros, loop structures with break statements, and so on. It's not impossible (at least in Scheme), but it is hard. In addition, syntax-rules is based on a DSL. If you want to build a macro that cannot be expressed in that DSL, or is hard to exress in that DSL (fairly common), tough. With imperative hygienic macros (provided they give you control over hygene), or imperative unhygienic macros, this isn't a problem.
- bitwize 10y agoThis is why R7RS has syntax-case. HOWEVER... various bugs can be easily introduced if your macros are not hygienic. For many use cases, syntax-rules will suffice, but when you use syntax-case you must explicitly break hygiene. It is a parallel situation to languages like Rust where unsafe operations are sometimes required, and therefore provided by the language but you must explicitly flag them "unsafe".
- qwertyuiop924 10y agoThat's... very wrong. >This is why R7RS has syntax-case. It doesn't. In fact, sc-macro-transformer is a candidate for inclusion in r7rs-large. >HOWEVER... various bugs can be easily introduced if your macros are not hygienic. That's true, but you're confusing hygienic/unhygienic with imperative/declarative. sc-macro-transformer, syntax-case and friends are all hygienic imperative macro systems. So none of that matters.
- rwallace 10y agoImperative unhygienic macros are what Common Lisp has, right? So you're pretty much guaranteed you'll be able to do whatever you want to do, the tradeoff being that you are responsible for watching out for unwanted name capture?
- qwertyuiop924 10y agoYes, although I'm a fan of imperative hygienic macros myself.