Is metaprogramming useful?

Brad Anderson brad at dsource.org
Wed Nov 29 08:25:43 PST 2006


Jarrett Billingsley wrote:
> "Brad Anderson" <brad at dsource.org> wrote in message 
> news:ekhh7s$2e7$1 at digitaldaemon.com...
> 
>> Poor Lisp.  It just sits there, 50 years old, debugged, optimized, and 
>> ready
>> to go, while the imperative languages try to inch closer over the decades.
> 
> In that case.. it'd be another interesting experiment to try to come up with 
> a new syntax for Lisp that appeals to more programmers than it does now ;)

But the existing prefix notation is exactly why it can be extended so many
ways with macros.  Change that and you lose most of, or at least a lot of, the
metaprogramming facilities (see Dylan).  You don't even have Lisp anymore.
It's why I'm skeptical of how far imperative languages can go with
metaprogramming before it turns into an awful beast.

I kind of hope I'm wrong and D can pull a lot of it off.  As Georg said, Lisp
is scary in its breadth and capability.  As Steve Horne lamented, there are no
high-level standard libs, because it's so easy to roll your own.  Any standard
lib that's come along has not served the needs of all, so they roll their own
anyway.  Those two things have slowed the adoption of Lisp.  Potentially
syntax, too, see below.

My original post in this thread was more of an observation that languages keep
getting more sophisticated, because the power users drive the compiler writers
further and further.  D is here because C++ can't grow as nimbly as it used
to, and Walter has some cool ideas to add to it.  And here's Lisp, sitting
there, arguably the most powerful language ever created, and people are afraid
of its power, its syntax, its (insert excuse here) so they choose to
reimplement.  I'd hate for people to get pretty far, hit a wall on something,
and then look and see how easy it is to do in Lisp.  On the other hand, I
would never try to quash the efforts people in D-land make.  It's just an
observation and a curiosity on my part.  Maybe Lisp isn't all that I'm giving
it credit for.

> 
> I really can't get past the parentheses.  I know Georg said it's an excuse, 
> but I really, truly cannot understand most Lisp code because I can't tell 
> which right paren out of a group of six is closing which left paren.  I'm 
> sure bracket highlighting in a code editor can help, but why should that be 
> necessary?  I'm sure a good deal of those parens can be stripped out, or 
> replaced by other brackets, or just moved around to get a more algebraic 
> syntax. 

That's probably because you're comfortable with the imperative langs, and 'C'
style.  Once people get over DVORAK keyboards, they claim the difference is
amazing.  S-expressions and prefix notation really is a powerful thing once
you see all the benefits.  You don't have to do quoted blocks like Nemerle.

And most people get past their difficulties of parens with indentation

#(defun save-db (filename)
#  (with-open-file (out filename
#                   :direction :output
#                   :if-exists :supersede)
#    (with-standard-io-syntax
#      (print *db* out))))

The parens on the end don't really matter.  It's where the indenting starts.
And of course, good editors take care of the parens and the indenting.  Even
without the metaprogramming facilities the prefix notation allows, you end up
with programs that speak more directly to the problem you're trying to solve.
 That may just be functional languages in general, though, ending up with code
that seemingly is a language designed for your domain.

For the uninformed, check out this great online book.  I've only given two
chapters: a whirlwind tour, and macros.  Even if you're hooked on D, this
makes you think differently about programming, and got me thinking of cool
uses for delegates in D and much more.

Quick Intro:
http://gigamonkeys.com/book/practical-a-simple-database.html

Macros:
http://gigamonkeys.com/book/macros-defining-your-own.html

For D to approach some of this extensibility would be phenomenal, and as Georg
suggested, we may be closer than anyone suspects..

BA



More information about the Digitalmars-d mailing list