Notes on D future

bearophile bearophileHUGS at lycos.com
Wed Aug 29 00:20:03 PDT 2007


I have just read the interesting document "WalterAndrei.pdf" recently linked here. I don't understand all the things it says, but here are few notes:

Page 17-18: the support of pure functions look like an intelligent idea, but I don't know their syntax, how they will be/look, etc.


Page 23-25, polysemous values: they will be useful for various things, not just integers. But I don't think they help avoid other kinds of integer overflow/undeflow (some of them are avoided by the Delphi compiler), like adding two big integers that produces wrap-around, etc (eventually such extra cheeks on integer operations can disabled by the -release compilation flag).


Page 33: I think some of those "optimizations based on constant folding" can be done from just a single function (that the compiler automatically transforms into a kind of "template", copying it as necessary), using some partial compilation on a copy of the function itself. So a function like:
int foo(int x, int y) {...}
If called like:
a = foo(something(), y);
b = foo(3, y);
Can be automatically managed by the compiler as it was a pair of:
int foo(int x, int y) {...}
int foo(int x)(int y) {...}


Page 52: can't the compiler automatically unroll little loops based on constant intervals/loop vars? (another compilation flag like -unroll can added, if necessary). I presume "static foreach" is a way for the programmer to tell the compiler that he/she really wants such unrolling done, so if such unrolling isn't possible, then the compiler must raise a compilation error instead of just silently leave the loop unrolled. At the moment I think tuples are looped with a implicitly static foreach. Is such implicit "static" going to become explicit and necessary? So this raises a compilation error:
void foo(Types...)(Types args) {
  foreach (arg; args)
    bar(arg);
...
And you must write:
void foo(Types...)(Types args) {
  static foreach (arg; args)
    bar(arg);
...

Bye,
bearophile



More information about the Digitalmars-d mailing list