Is metaprogramming useful?

Andrey Khropov andkhropov_nosp at m_mtu-net.ru
Wed Nov 29 15:47:37 PST 2006


Steve Horne wrote:

> : 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.
> 
> In semantic terms that's true, but in syntax terms it's not - at least
> not without going to the extreme compiler building stuff I mentioned
> earlier. Lisp may provide the ability to set up whatever semantics you
> want, but if you have to access that through a syntax that you just
> can't get on with, that's a serious handicap. And the 'what they beg
> Walter to do for them' is probably as much about syntax as semantics.

I agree. Good point.

I have to admit - Lisp in the most powerful language I'm aware of. 
But it doesn't have much syntax sugar for common operations.

And everything looks the same.

Take this chunk from spectralnorm program from the shootout for example:

---------------------------------------------------
(dotimes (i n)
          (incf vBv (* (aref u i) (aref v i)))
          (incf vv (* (aref v i) (aref v i))))
---------------------------------------------------
I think D is a bit more readable and concise:
---------------------------------------------------
    foreach(i, vi; v)
    {
        vBv += u[i] * vi;
        vv  += vi * vi;
    }
---------------------------------------------------

-- 
AKhropov



More information about the Digitalmars-d mailing list