While doing some unrelated research I stumbled upon my very first email to Walter, dated April 26, 2004. I liked to see from today's perspective where a great collaboration and friendship have started. I thought others would also enjoy to see it, so I'm sharing it with Walter's approval and a few minor edits.

On 4/26/04 6:54 PM, Andrei Alexandrescu wrote:
[Walter: I'm going to be ruthless. Put your bulletproof vest on.]

Hi Walter, this is Andrei, we met at SD in Santa Clara.

I was bitching to myself and then together with a friend (e-meet
[...]) about how hard it is to do metaprogramming in C++. He
mentioned D is much better at it, and we browsed the online
documentation for D's templates
(http://www.digitalmars.com/d/template.html), which we noticed
(apologies if I am wrong) is not much more more than a
cleaned-syntax version of C++'s templates, which in turn are
 [...].

That sucks.

So I said I'd give you the highest order bits of what I think what a
better language for metaprogramming ought to be like. In spite of my
ruthlessness, please accept this as a statement of hope that you'd
be willing to think about this and do something about it.

A metalanguage should bear the same programming style as the base
language that it serves. I think that's only fair: the programmer
learns one syntax and set of semantics (e.g. conditionals,
iterations, objects...), and applies it as transparently as it gets
to both metaprogramming and regular programming. C++ has a rich
mixed-mode language for straight programming, and a half-assed (or
should I say quarter-assed) functional language for metaprogramming.
You carried this schism in D, while just cleaning the corners.

Terrible. If you have conditionals, iteration, functions, and objects
in D's straight programming support, you should have conditionals,
iteration, functions, and objects in D's metalanguage. (I'm not
asking for things like virtuals, exceptions, contracts, and other
higher-order stuff on grounds that metaprograms are usually smaller
and aren't subjected to as many scale issues as regular programs
are.) Those should be combined with introspection primitives, such
as:

* The venerable typeof

* For a class, enumerate all of its members, and figure out their
attributes (protection level, static or not, type...)

* For a module/namespace, enumerate all of its symbols and figure
out their attributes.

* For a function, figure out its return type and the type of each of
its formal arguments.

* Figure out if a certain function exists (that should be easy if
you have the tools above). That will be useful to decide, for
example, if an iterator supports random access.

* And if you really want to go meta, define metacode that can take
an AST node as a parameter and can visit the AST and figure out what
each node is. That would allow things such as loop fusion and other
advanced stuff. But for now, let's leave those aside.

Does anything make sense so far? :o)



Andrei

Reply via email to