A D vs. Rust example

Ali Çehreli acehreli at yahoo.com
Fri Oct 28 16:18:51 UTC 2022


On 10/28/22 00:25, Ola Fosheim Grøstad wrote:
 > On Thursday, 27 October 2022 at 23:40:11 UTC, Walter Bright wrote:
 >> The fact that D's GC is what enables advanced CTFE programming is
 >> often overlooked. It's a killer feature enabling a killer feature.
 >
 > It is clearly better to use high level code in CTFE than system-like
 > code.

Yes, high level code is always better.

 > Maybe you could consider adding more high level features such a
 > comprehensions and generators for the purpose of improved CTFE?

I want to ask comprehensions and generators as seen in the context of 
Python but you could not have meant it because Python does not have CTFE.

D uses range algorithms for comprehensions and generators. For example, 
the following program instantiates a struct template with a value 
computed from a generator:

struct S(size_t N) {
     float[N] arr;
}

void main() {
     import std.algorithm : map, sum;
     import std.range : iota;

     auto s = S!(iota(10).sum)();  // <-- Generator used in CTFE
     pragma(msg, s.arr.length);
}

Ali



More information about the Digitalmars-d mailing list