November 25, 2002
ll1-discuss on macros

On the ll1-discuss mailing list there has recently been a lot of discussion of lisp-style macros. One of the funnier threads started when Todd Proebsting posted a message with the subject "Macros Make Me Mad":

Defining a macro is often an act of defining a language construct and implementing it. Reasonably or not, I hold language constructs to a higher standard than, say, a mere function definition. Specifically,

  • I expect language constructs to be implemented perfectly. I must trust my compiler.
  • I expect language constructs to be documented precisely. I must trust the documentation.

Which is a pretty bogus complaint, I thought.

Guy Steele replied with a series of messages of the form

  • I expect <language feature> to be implemented perfectly. I must trust my compiler.
  • I expect <language feature> to be documented precisely. I must trust the documentation.

where <language feature> was classes, procedures and algebraic expressions. Steele finished with Parodies make everyone mad:

My point is not that Todd should lighten up on macros; on the contrary, if anything, I would say he expects too little of those who define functions. All too many programmers *are* really lousy at writing documentation. A library of procedures or methods can constitute just as big an extension to a language as a handful of macros.

Where the line is drawn will depend to some extent not only on the skill level of the programmer but also on the customs and expectations of the community within which the programmer functions. If macros are part of the customary toolset of a community of programmers and there are guidelines and expectations about how they are and are not to be used, and about the level of documentation needed, then they need not be a problem. The same is true of classes, procedures, and algebraic expressions---and there was a time and place in the history of computers when each of these was regarded with similar suspicion by some group of (non-stupid) programmers.

Macros are one of my favorite, and most unique features of lisp. I'm a little touchy when they're criticized, so I'm glad that Steele answered Preobsting's point so well (while still not letting macros completely off the hook).

Posted by jjwiseman at November 25, 2002 01:09 PM
Comments

I worked with Todd for a few months on C#. Everytime he described some language feature he liked, I would shrug and say "that's just a macro in Scheme". For people not immersed in macros, it's weird for language features to come "a la carte" like libraries.

FYI: The ML community is perfectly happy without macros. What's the difference between macros and functions? Not much, they say. I tend to agree.

Posted by: Pinku on January 9, 2003 09:43 AM

The consensus on the ll1 thread seemed to be that macros and functions aren't very different, except that macros can be more convenient--until Steele came up with a couple macros that depended on having access to the lexical form of the code body. Macros that symbolically differentiated the function being computed, for example.

Posted by: jjwiseman on January 15, 2003 11:24 PM

Don't macros move some of the processing from execution time to parse time, as compared to functions?

Posted by: Jeremy Leader on January 24, 2003 03:08 PM

Yes, and that is one advantage they can have.

Posted by: jjwiseman on February 11, 2003 10:03 PM
Post a comment
Name:


Email Address:


URL:




Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)

Comments:


Remember info?