Re: Macros (was Re: Noob Wonders: Lisp-1 vs. Lisp-2
- From: Kent M Pitman <pitman@xxxxxxxxxxx>
- Date: 13 Jan 2008 01:24:52 -0500
tim Josling <tejgcc_nospam@xxxxxxxxxxxxxx> writes:
It's interesting that other languages have been importing many features,
but macros seems to be an exception. My impression is that macros are less
used now than 10 or 20 years ago.
Yes. I think that's for a number of reasons, but basically because
the trend has been toward static analysis and macros themselves are
hard to debug without a decent theory of parsing, presenting language
structures, etc. Without that, they are little more than a sed
script, and that detracts from the other less unruly (more ruly?)
parts of whatever language you are talking about.
There seems to be a phobia about macros. People keep reinventing them but
are very wary of calling them macros.
Well, they keep trying to solve the problem in isolation, without
addressing the other parts of the language (manifest representation,
parsing, printing) issues that make it tough to use them. If you want
to solve only the macro problem in isolation, it is a hard problem,
and they're doing the best they can--much better, frankly, than I'd
have predicted, even if not as well as we might wish. I'm pretty
impressed with how much C# managed to clean up templates, to where
they almost feel like they're part of the same language and not some
alien language, unrelated to the base language (as happens in C++).
If you have a look at the java world, there is a large amount of code
generation going on. There is also an amazing amount of patching of object
files (.class files) as well.
C++ has templates, which have reportedly now reached the stage of being
Turing-complete. But macros are still frowned upon.
Probably because of debuggability, which in turn is because the
language you're writing your template code in really doesn't feel like
the language you've come to master without templates... so it doesn't
leverage a lot of what you know already. It's just a new exercise.
There are two explanations I have seen:
1. If you use macros, you are almost defining a new language. You have to
look at the macro definition to see what the code does. [...]
You are only defining a new language if you don't make your original
language available as a manifest data structre that is easy to
conjure, traverse, parse, and print. What modern language, and here
I'll generously include not only C++ but even C, is incapable of those
four basic operations? The thing that is missing isn't the ability to
manage such structures, it's the ability to know and manipulate and
interact with and extend the actual structures C++ does.
What's people like about Lisp, I think, is that it allows you to take
ordinary knowledge--the kind of knowledge you have already if you've
solved that idiotic FLATTEN-LIST problem that teachers of Lisp always
assign--and use that to write a macro. C++ templates are
unintelligible to someone who does not have reasonably advanced
knowledge of types and methods. That's a huge difference. You could
get a lot of programming done in Lisp without ever mastering defclass,
defstruct, deftype, and typep; to include the use of macros. Not so
in C++ for the equivalent operators.
2. In the early days, people went too far with macros and the code became
unmaintainable.
This seems to be just an argument for discipline in programming projects.
I think it tells you that the tools for creating macros were
error-prone because they were text-based, and they got a bad name
because of token merging bugs and stupid stuff like that. That makes
it politically hard to get people to reconsider them. They have the
kind of overzealous bad reputation that Lisp has in some
circles--where people are eschewing a whole class of concepts because
once, somewhere that they probably don't remember, they saw (or heard
about or think they heard about) one such concept being abused.
Is there any other explanation? Here is Sun's explanation for no macros in
Java.
http://www.artima.com/weblogs/viewpost.jsp?thread=5246
Fascinating. But personally, I think the central claim in that post
appears to be unsupported. That is, they seem to assert that macros
would make programs unreadable for everyone else. But they offer no
foundation for this claim. That says a lot.
Probably people are not beating down their doors asking for macros.
People rarely ask for things they are not used to using, and are
usually delighted to get anything that improves their prior state,
with very little regard to whether others somewhere else have
something better. They have to first understand and appreciate that
"something else" to want it, and no one is busy marketing macros to
this community in a form that makes it sound like something they
_would_ want.
For a long time, people used to talk about what an innovation
Microsoft Windows was, mostly because they came from DOS, not the
Macintosh, and certainly not from a Lisp Machine, an Alto, a Dorado,
an Apollo ... Unix (and later Linux) was likewise greeted as an
extraordinary step up by people who had never seen Multics. Progress
often moves backward to move forward because timing, marketing, and
other factors are as important as being right about where you're
going...
- - - - -
By the way, shifting topic for a moment somewhat:
The first course I took at MIT where Lisp was taught was 6.030, I
believe, and I think I took it in the spring of 1977, almost exactly
30 years ago. The Lisp part was taught by Joe Weizenbaum (of ELIZA
fame). I recall a story he told us once about the importance of
always balancing our parens. He took on a mischievous tone at one
point and said something vaguely to the effect of (this was now almost
exactly 30 years ago, in Spring 1977, and this is from memory, so I
might not have the exact words still, but hopefully this is close in
nature): ``Sometimes, when I want to have a little fun with someone,
I'll sneak into their office and write a stray open parenthesis
somewhere on their blackboard. [And he made a little chalk mark to
show us.] And then all day, I imagine they'll wander around feeling
like something is just a little off. Then, later, I'll sneak back in
and close that parenthesis. [He made another chalk mark.] And then
the world will be back in balance, and they may never know why.'' And
he smiled the kind of delighted smile of someone who understood the
power of parentheses to make or break one's day. The remark, or its
essential nature at least, really stuck with me. And I often think on
it and smile.
I noticed you missed a closing parenthesis in the subject line. And
so I was feeling like something was just a little off.
:) <-- Balance restored. I hope you don't mind.
I feel better now.
.
- References:
- Noob Wonders: Lisp-1 vs. Lisp-2
- From: are
- Re: Noob Wonders: Lisp-1 vs. Lisp-2
- From: Don Geddis
- Macros (was Re: Noob Wonders: Lisp-1 vs. Lisp-2
- From: tim Josling
- Noob Wonders: Lisp-1 vs. Lisp-2
- Prev by Date: Re: How do lispers do their GUI programming anyway?
- Next by Date: Re: Macros (was Re: Noob Wonders: Lisp-1 vs. Lisp-2
- Previous by thread: Re: OT: how to punctuate rhetorical questions
- Next by thread: Hutchentoot or Allegroserve?
- Index(es):
Relevant Pages
|
|