Compile time values & implicit conditional mixin, as an alternative to tertiary operator hell and one-compile-time functions.

Max Haughton maxhaton at gmail.com
Sun Jan 17 02:02:00 UTC 2021


On Sunday, 17 January 2021 at 00:28:02 UTC, Paul wrote:
> On Saturday, 16 January 2021 at 16:23:18 UTC, Paul Backus wrote:
>> This is true no matter what you do, because `enum` constants 
>> are immutable. Their value has to be computed in a single 
>> expression, and once assigned, it can never change.
>
> Wouldn't it make sense to also have a mutable compile time 
> variable though?
> I don't know about implimentation etc, but semantically I find 
> it strange there isn't.
> (Instead of running 'normal' code to retrieve a value from it 
> to be assigned to an enum constant since it couldnt be made 
> from the get go)

They would have the potential to make compiling really hard if 
they were allowed freely. If you imagine a mutable enum at module 
scope, it could be modified all over the place and lead to 
completely non-deterninistic compilation.

Some mechanisms to (say) add to a table at compile time might be 
useful (you can fake this using ELF sections), but mutability is 
a footgun


More information about the Digitalmars-d mailing list