Playing arround with mixin - alias?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 21 02:44:07 PDT 2017


On Friday, April 21, 2017 09:31:52 Martin Tschierschke via Digitalmars-d-
learn wrote:
> Is it possible to define an alias for something like
>
> mixin(import("local_function_file.d"));
>
> to write only
>
>     use_local_function;
>
> which will be translated to:
> mixin(import("local_function_file.d"));
>
> (this additionally needs the file local_function_file.d in
> source/ +
> -J./source as parameter for dmd aka.  dflags "-J./source" in
> dub.sdl)
>
> Regards mt.

You can alias symbols. You can't alias statements, and mixins are always
explicit. Now, you could have a function that returned what you wanted to
mix in so that you just did something like

mixin(use_local_function());

and have use_local_function return whatever code it is you want to mix in,
but you can't just do something like

use_local_function;

and have it work. That would be more like a macro system, and D doesn't have
that. We have string mixins and template mixins, but those are both
explicitly mixed in.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list