enum strings in import

Quirin Schroll qs.il.paperinik at gmail.com
Mon May 2 12:03:20 UTC 2022


On Wednesday, 27 April 2022 at 15:23:32 UTC, IGotD- wrote:
> Reading this concept it is clear that we need to change import 
> to allow enum strings.
>
> https://github.com/dlang/phobos/pull/8309
>
> It can be done with mixins but the code becomes ugly. Instead 
> compile time string enums should be accepted in the import 
> argument.
>
> The question is how to do this.
>
> enum string somewhere = "location";
>
> import this.that.somewhere.here;
>
> This might fool many users and they start to look for the 
> folder "somewhere" which might not exist. In order to clarify 
> that you are using a compile time string you can be more 
> obvious like.
>
> import this.that.enum(somewhere).here;
>
> Now it is more obvious that somewhere is a variable.
>
>
> Another thing that I also noticed is how the version 
> identifiers are just a sea of identifiers, many not orthogonal. 
> Wouldn't it be time to let version have an argument. Like
>
> version(OS == Windows)
> {
>
> }
>
> This would it simpler for the import, then we could use.
>
> import this.that.version(OS).here;

The simplest solution is to allow `mixin(expression)` not only to 
generate declarations, expressions and statements, but also to 
generate identifiers. So you’d have
```D
import a.b.mixin(somwhere).here;
```
This has been proposed like a thousand times.


More information about the Digitalmars-d mailing list