Is metaprogramming useful?

Steve Horne stephenwantshornenospam100 at aol.com
Wed Nov 29 13:01:17 PST 2006


On Wed, 29 Nov 2006 14:11:01 -0500, Brad Anderson <brad at dsource.org>
wrote:

>Steve Horne wrote:
>> On Wed, 29 Nov 2006 11:47:10 -0500, Brad Anderson <brad at dsource.org>
>> wrote:
>> 
>>> I don't think this is the primary reason.  As mentioned before, syntax is a
>>> part of it, but so is the total power given to the programmer.  This power
>>> leads to a lack of standard or cohesive libs, b/c it's so easy to make it
>>> exactly the way you want it.  I imagine that if some of the D power users
>>> wrapped themselves in Lisp for a while, they'd be able to do for themselves
>>> what they beg Walter to do for them in D.
>> 
>> Not really.
>> 
>> There are things you just can't do with Scheme macros. Associativity
>> and precedence, for instance. This means that if you want to do these
>> things, you have to go the Von Neumann route - treat code as data and
>> manipulate it at compile time using Scheme functions.
>
>I'm not following.  Do you have definitions or examples of these?  I did find
>this...

Sorry, I'm being stupid. On reflection, you're asking for examples of
things you can't do with Scheme macros.

Well, it's hard to provide examples of things that can't be done
beyond listing them. Disproof by example is much stronger than proof
by example. If your link gives examples of precedence and
associativity using macros, well, that just makes me twice stupid.

The claim about associativity and precedence, though, just fell out of
my reading of the Scheme manual. At the time, I could see no way to do
it.

I'm aware that it is possible to build them in by creating an
unambiguous set of BNF rules for a grammar (as opposed to the more
normal approach of using disambiguating rules) but I couldn't see a
way to do either. I had the distinct impression that the matching is
always from left to right.

Based on that, you can write (1 + 2 * 3) if you want, but the result
will be 9, not 7.

-- 
Remove 'wants' and 'nospam' from e-mail.



More information about the Digitalmars-d mailing list