__FILE__ and __LINE__ in case of import expression

Andrey Zherikov andrey.zherikov at gmail.com
Fri Aug 21 20:44:06 UTC 2020


On Friday, 21 August 2020 at 15:27:14 UTC, Adam D. Ruppe wrote:
> On Friday, 21 August 2020 at 14:01:24 UTC, Andrey Zherikov 
> wrote:
>>     mixin(import("foo.d"));  // line #17    (2)
>
> Why are you doing this? This kind of thing is almost never an 
> ideal solution in D.
>
> See, the compiler just sees a big string literal there. It 
> isn't a separate file at that point, the import expression just 
> pastes in the file contents as a string, and then mixin makes a 
> chunk of code from it.
>
> These two features are not really meant to be used together, at 
> least not without some custom translation code in the middle.

Currently this is for illustration only but why can't I do this?
This can be an alternative to `rdmd --eval` that takes code from 
a file, not as CLI parameter.



More information about the Digitalmars-d-learn mailing list