Subject: Re: Macro-writing in CL
From: Erik Naggum <erik@naggum.net>
Date: Thu, 07 Jun 2001 13:19:02 GMT
Newsgroups: comp.lang.lisp
Message-ID: <3200908738061425@naggum.net>

* "Biep @ http://www.biep.org/" <reply-via@my-web-site.com>
> (1) People like you and me have come to grips with the intricacies of macro
> writing, know the pitfalls and how to avoid them, and may even have the
> status of "macro guru".  This is somewhat like Mel in the story
> (http://www.brabandt.de/html/jargon_49.html).  I think the very fact that
> there are macro gurus indicates that there is a problem: the basic notion
> of a macro is very simple, yet it is not trivial for a novice to go and
> write good macros.

  How can you both invent _and_ lament the macro guru at the same time?
  There is no such thing as a macro guru.  There are, however, macrophobes.

> (2) Macros are (or should be) about meaning one thing when you say
> another -- not necessarily about transformations, even though the notions
> come close.  (To appreciate the difference, see what C macros can do that
> they shouldn't..)  Let me just give a few examples:

  Macros are in fact implemented as transformations.  What you make of them
  is up to you.  Ingenious use of macros can make some things very easy to
  understand.  Idiot use of macros make things harder to understand.  What
  else is new?  Incidentally, every "should be" betrays an agenda.  Before
  things "should be", study what they _are_.  Your problem is that you
  started to "should be" before you understood how things are.  (This has
  been evident for a long time, by the way.)

> There is a subtle but fundamental difference between the notions of 'fresh
> variable' and '(gensym)'.  The latter is a kluge to arrive at the former
> (or the right thing to do in other contexts, of course).

  So you choose to rebel against the obvious, and call things "kluge" that
  are simply means of achieving something you need.  What else is new?
  Rebels _are_ usually clueless.  This is how we do these things.  If you
  do not like it, invent something better.  Criticizing without improvement
  is just so much useless whining.

> There is a difference between 'the list function' and '(list ...)'.
> CLtL2 has 'solved' the resulting problem by requiring that no built-in
> function can be redefined, but that is of course a weakness bid.

  Could you try to _explain_ your mindset instead of giving examples that
  make sense only to yourself?

> Lisp has fought hard to get rid of (default) dynamic scoping, but in macros
> this is still the default.

  Really?

> If your macro references a variable X, it just grabs whatever X happens
> to be available at the location where the macro is used.

  This is not what we call dynamic scope.

> Like dynamic scoping for lambdas, people who have gotten used to that
> tend to like it, and indeed can proffer a whole battery of situations
> where this 'feature' can be exploited -- again the guru phenomenon.

  When will it occur to you that _you_ are actually inventing the gurus?

> Normally you mean 'this variable' but have to write 'X', again not quite
> the same thing.  As with functions, lexical scoping (referential
> transparency) should be the default, with an option for dynamic scoping.

  That _is_ the situation today.

  FYI: people have written macros that hide the mechanics of "fresh
  variables".  Those should arguably have been part of the language, but
  they are not, for whatever reason.  So it is part of the oral tradition.
  Big deal.  Learning to do anything well requires effort.  If instead of
  learning you rebel against the effort, you will never do it well, and
  that itself will be an argument in favor of not doing it the way it
  should be done.

  I submit that the way you have treated macros in Common Lisp is exactly
  the same way that turn people into criminals.  Rather than understanding
  the existing set of rules and living within them, they break them out of
  sheer ignorance and arrogance, then the rules hit them back, because they
  are not quite as arbitrary as the whim of those who break them, and they
  get _another_ reason to break the rules: The rules are bad and they hurt
  you.  If you want to break the rules, first you must understand them and
  then break them by achieving what they were intended to achieve better
  than the rules already achieve, such as by eliminating a negative side
  effect.  Otherwise, there is no constructive element in breaking the
  rules, only destructiveness, and that is never appreciated, except
  possibly by others of the same rebel inclination.

> (3) So since the macro writer wants to state "whenever I say this I MEAN
> that", but the system wants to hear "whenever you say this, I should
> assume that you SAID that", macro writing necessarily involves fighting
> the system.

  What if you got it all wrong?  What if _you_ are fighting "the system"
  only because you have misuderstood what "the system" is doing and how it
  works?

> It is a lot like legalese: a lawyer is also a guru in bringing a meaning
> across in a system that tends to look at texts, but it involves
> non-trivial phrasings, and often a lot more text than one might have
> thought.  If a non-guru draws up a legal document, it is likely there are
> loopholes.

  And the problem here is what?

> Does that help?  Again, if you are familiar with the system, the
> "macrolese" may come naturally, and even appear obvious, and definitely
> prove exploitable in ways that a "correct" solution would not be -- again
> the comparison with lawyers comes to mind :-)

  An analogy to a skilled craftsman versus an unskilled craftsman comes to
  _my_ mind.  Maybe that is because I happen to think that the idiotic
  attitude problem many people have towards lawyers is based in exactly the
  same willful and arrogant ignorance of "the system" that those who hate
  macros or Lisp in general suffer from.

  This is only a problem with _your_ approach to macros, "Biep @
  http://www.biep.org/".  If you could bother to study how it works and try
  to learn to use it properly, you would probably be able to find a way to
  express what you need, just the way you want to express it.  You see, the
  whole idea with macros is expressibility.

  Simply put: If you do not want to learn the language, do not blame the
  language for your inability to express yourself in it.

#:Erik
-- 
  Travel is a meat thing.