import(__FILE_LITERAL__)

user1234 user1234 at 12.de
Mon Sep 9 19:33:38 UTC 2024


On Monday, 9 September 2024 at 18:18:31 UTC, monkyyy wrote:
> Import Expressions are limited and had to use in abstractions 
> because they require the user to pass `-J=.`, which given the 
> average d user uses dub; suggesting such a thing requires a 3 
> step process.
>
>> Note that by default an import expression will not compile 
>> unless one or more paths are passed via the -J switch. This 
>> tells the compiler where it should look for the files to 
>> import. This is a security feature.
>
> My opinion on the subject may violate the dip forum guidelines.
>
> ---
>
> I suggest that its safe to read the file the user is compiling 
> during compilation. I suggest that new special token that 
> generates ... something that an import expression can take 
> without a `-J=.`.
>
> ```d
> import foo;//lolz
> import std;
> enum string=import(__FILE_LITERAL__).split('/n').front;// 
> "import foo;//lolz"
> ```
>
> By separating it into two step process you could use the 
> special token magic
> `void foo(alias file=__FILE_LITERAL__,int line=__LINE__)(){`

I think that would work but I have two details in mind

1. should it be expanded to a relative or absolute path ? 
Remember why __FILE_FULL_PATH__ was created.
2. that feature means leaking the file in plain text.

And finally, what's the use of that feature, maybe allow to 
program a compile-time Quine, but what else ?

In D reflexion is supposed to work with `__traits`.


More information about the dip.ideas mailing list