__ARGS__ : allow access to (stringified) arguments, as C's `#arg` macro

Timothee Cour thelastmammoth at gmail.com
Fri Jan 19 10:41:40 UTC 2018


> Not sure I understand this feature. Is it something like:
>
> auto foo = 3;
> auto bar = 4;
> log(foo, bar);
>
> Would print?
>
> main.d:3 foo=3
> main.d:3 bar=4

main.d:3 foo=3, bar=4 (or whatever formatting is applied given
supplied stringiified arguments, that's irrelevant as it can be
customized inside user code)

> If that's the case then this seems like yet another hack because we don't
> have AST macros.

I predicted you'd mention AST macros. While I agree AST macros would
solve this and other problems, the likelihood of them appearing in D
in the near future is slim. My proposal is pragmatic and can be
implemented with a short PR in the near future, if people agree on
this change. If/when AST macros come to D, we'd still be able to use
them for that purpose.

Currently there is *zero* good workaround:
* either calling code is ugly (https://github.com/dlang/phobos/pull/4318)
* or compile time is slowed down a lot (as I showed in my original
post, via import(__FILE__)[__LINE__] + redoing the work the compiler
already did)

This proposal is simple to implement, useful, and exists in other
languages (C++ and many others)


More information about the Digitalmars-d mailing list