compile-time variables?

David B. Held dheld at codelogicconsulting.com
Sat May 26 11:07:35 PDT 2007


Bruno Medeiros wrote:
> [...]
> It's more specific than that. Like "welcome to D meta-programming". 
> Meta-programming in other languages, like macros in Lisp, are done as 
> normal Lisp code and thus also have state (as I believe you know already).
> In D that's not the case, and I find it interesting, and even kinda of 
> funny and ironic, that D meta-programming is a *completly* pure 
> functional programming world :P . Funny and ironic because the first 
> thing that poped to mind when I first "entered" D meta-programming, was 
> the Scheme pure functional programs we (me and my fellow colleagues) did 
> some years ago in my college's first-year, SICP-based college course. :)

It's true that D shares C++'s pure metaprogramming facilities, but I 
think it is fairly easy to see why.  Both of these languages already 
know how to do constant folding and template instantiation, which don't 
require any heap management.  Since dynamic languages like Lisp 
generally have a runtime evaluation engine, running that in the compile 
phase is no big deal, whereas it's a lot less trivial to do that in D 
(though Walter allows dynamic strings as the exception to the 
compile-time heap rule).

Perhaps D should support phased compilation, but I think a better 
approach would be to have better support for functional programming (if 
functions were really first class values in D, you could create them as 
easily as the builtins and do so at compile time, which would make it 
possible to do things like monads).

Dave



More information about the Digitalmars-d mailing list