Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!gerber!jaffer From: jaffer@gerber.ai.mit.edu (Aubrey Jaffer) Newsgroups: comp.lang.scheme Subject: distinguishing macros from combinations Message-ID: <13849@life.ai.mit.edu> Date: 10 Mar 91 04:42:31 GMT Sender: news@ai.mit.edu Lines: 41 doug@snitor.uucp (Doug Moen) brings up some important points: The main problems with traditional macros are: 1. They must be defined to the system before any code using them is loaded; this is a common source of obscure bugs. 2. They are usually global; macros can be made to follow lexical scope rules, but many people find the resulting scope rules confusing. 3. Unless they are written very carefully, macros are vulnerable to inadvertant capture of free variables; to get around this, macros may have to generate code in which procedure values appear as quoted constants. 4. There is a similar problem with syntactic keywords if the keywords of special forms are not reserved. If keywords are reserved, then either macros introduce new reserved words, invalidating old code, or else special forms defined by the programmer do not have the same status as special forms defined by the system. Problem 1. could be solved by specifying that macros are lexically scoped EVEN AT TOP LEVEL. The order of definitions would then not matter. This would require that loaded files be loaded twice; a two pass lexical system. Macros typed at top level would then be at the users own risk (because code already expanded would not be changed); But this is already the situation in lisps. I think that 3. is solved by Hygenic Macro expansion. Problem 4. can be alleviated by not allowing reserved symbols to be bound in macros (just as they cannot be bound by lambdas). The number of reserved symbols is small enough that this should not present a hardship. Using a prefix character (like `&') to prefix all macro names has the additional benifit that, even if the Scheme standard committees do not put this in the specs, it can be used as an element of style, much as most C programmers use uppercase names for #defines. If a programmer wants to have ALL special forms similarly marked all he has to do is define the macros &IF, &DEFINE, &COND, etc to expand to IF, DEFINE, COND, etc.