[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macros and little languages

   Date: Fri, 24 May 2002 20:41:39 -0400
   From: Howard Stearns <stearns@curl.com>

   Is it more important for a language to promote code that is readable by 
   anyone versed in the particular programming language, regardless of  the 
   application domain, or is is it better to for a language to make it easy 
   to churn out new code that works for particular applications?

I think this is a false dichotomy.

If you're trying to read and understand, let's say, GNU Emacs
extensions, there's simply no way you can do it without becoming
familiar with the "application domain", and this would be true even if
there were no macros whatsoever.  You'd have to know what the "point"
and "mark" are and what it means to "go forward" and so on.  That is,
you'd have to be familiar with the commonly-used *functions* and the
concepts they deal in.

As a susbystem has more and more widely-used functions, there's more
and more that you have to know in order to understand the subsystem.
That doesn't mean that it's a bad idea to encapsulate procedural
abstractions into functions, i.e. it would not be a good thing to
inline-expand functions in the source code all over the place, simply
to reduce the number of functions one must learn.

Well, the same goes for macros.  Admittedly, it is somewhat more
conceptually expensive to learn a new macro than to learn a new
functions, since macros are more powerful, and generally good
taste and good judgement rule that the threshold for deciding to
introduce a new macro is somewhat quantitatively higher than for
a function.  The principles are the same.

And the threshold for introducting a macro that people will find
familiar and fairly obvious is smaller than for introducing something
really novel.  An example of a fairly obvious one: someone who has
used Common Lisp will easily understand something like

  (with-internet-stream (s hostaddr port)
      (write-to-stream s "foobar"))

An example of one that would be novel (were it not in CL itself)
is "loop".