Is metaprogramming useful?
Brad Anderson
brad at dsource.org
Wed Nov 29 13:30:28 PST 2006
Brad Anderson wrote:
> Steve Horne wrote:
>> 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.
>>
>
> in a Lisp-like language, using prefix notation, this is:
>
> (+ 1 (* 2 3)) => 7
>
> or
>
> (* (+ 1 2) 3) => 9
>
>> On a quick scan through that, there doesn't seem to be anything to say
>> that Scheme macros can do associativity and precedence. That's fine by
>> me, as I don't feel quite as stupid as I did a minute ago ;-)
>
> There's no need for precedence, because it's always explicit.
>
> This thing is a dead horse. I suspect we are confusing each other, as you
> say. You should look at Common Lisp a bit, esp. the link I posted to Peter
> Seibel's book. Even a brief read may help you understand a bit of what I'm
> saying about metaprogramming.
>
> BA
Sorry, gotta kick the horse one more time.
http://plaza.ufl.edu/lavigne/infix.lisp
BA
More information about the Digitalmars-d
mailing list