Thesis on metaprogramming in D
Don Clugston
dac at nospam.com.au
Thu Nov 30 07:46:52 PST 2006
Daniel Keep wrote:
> Don Clugston wrote:
>> When I looked at the Nemerle website, I didn't see much that couldn't
>> be done easily with D templates. It would be interesting to find
>> something it can do, that D can't.
>
> > def sr = System.IO.StreamReader ("SomeFile.txt");
>
> Immutable run-time variables. You can assign anything to them, and then
> it can't change. AFAIK, D's const doesn't let you do that.
It does, but only for class member variables. There are two 'const's in
D, one for literal constants, and the other which is once-only assign,
and should probably be called 'final' instead.
class SomeClass {
const StreamReader sr;
this(char [] filename) { sr = System.IO.StreamReader(filename);}
};
[snip]
> > macro while_macro (cond, body)
> > syntax ("while", "(", cond, ")", body) {
> > <[
> > def loop () {
> > when ($cond) {
> > $body;
> > loop ()
> > }
> > }
> > loop ()
> > ]>
> > }
>
> Do THAT with templates :3
void While(lazy bool cond, void delegate() body) {
for (; cond; ) body();
}
<g>
Or if I can't have for() as a primitive:
void While(lazy bool cond, void delegate() body) {
loopstart: if(cond) goto done;
body();
goto loopstart;
done:
}
> It would be foolish to think that Nemerle isn't an amazingly powerful
> language. D is good, and its' templates are very powerful, but they're
> not THAT powerful.
>
> There is always more to learn :)
Very true.
It does seem, though, that Nemerle and D are exploring a quite similar
'paradigm space' (so there's probably quite a bit each can learn from
the other). Yet neither has really caught up with Lisp. Yet.
More information about the Digitalmars-d
mailing list