Is it possible to add items to the arrays and hashes at compile time?

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 10 13:01:19 PDT 2015


On Wednesday, 10 June 2015 at 17:43:36 UTC, Ali Çehreli wrote:
> On the other hand, if it's a manifest constant (enum, const 
> static, etc.) then by definition it cannot be mutated. If we 
> allowed mutation of compile-time expressions, then we would 
> have a complicated language.

Unfortunately, the halting problem says that the analyzer does 
not exist. Although I don't believe it!

> enum i = 42;
> enum j = foo(i);    // Did foo() use 42 or 43?
> i = 43;
> enum k = foo(i);    // Did foo() use 42 or 43?
>
> How can an enum value be changed? I find the above confusing.

So in fact, if `int` is evaluated at compile time, then we won't 
need constants or enums. Because they almost would not make 
sense. Although the issues associated with immutability, complex, 
I think they can be solved differently.

> The great thing about D's CTFE is that we can use arbitrarily 
> complex expressions as long as they are available at compile 
> time. For example, it is possible to make 'i' above a foreach 
> loop variable and call foo() with different values.

There is nothing great. Everything is based on constexpr of C++. 
I want something more revolutionary :)

> What is your use case? I feel like it can be solved by other 
> means.

There is no precedent special :) I just want to know more about 
the possibilities of D and the possibility of its compiler. D 
made me a terrible interest in compilers :)


More information about the Digitalmars-d-learn mailing list