Convenient debug printing

Neia Neutuladh neia at ikeran.org
Sat Feb 2 05:20:50 UTC 2019


On Fri, 01 Feb 2019 21:40:29 +0000, Meta wrote:
> His main argument, about not wanting people to be able to invent their
> own syntax and encourage fragmentation within the language community,
> does not ring true. All you have to do is look at Rust to see that it is
> possible to support a limited form of AST macro without any adverse
> effects.

>From what I've read, Rust macros allow you to define new syntax:

    let fib = recurrence![ a[n]: u64 = 0, 1 ... a[n-1] + a[n-2] ];

credit: https://danielkeep.github.io/practical-intro-to-macros.html

That "..." isn't a Rust language construct; it's defined by the macro (and 
only works within the macro's arguments, so you can't do a Pascal-in-C 
style `#define begin {`).

Even without defining new syntax, AST macros in C# have allowed things 
like database libraries that take normal lambdas. They're sufficient for 
writing an assertion tool that can take an expression, evaluate it, and 
print out every part of it for analysis if something went wrong.

An old DIP <https://wiki.dlang.org/DIP50> for AST macros in D suggests 
this strategy, along with implicit stringification of block statements 
belonging to a macro invocation and access to the context of the 
invocation. That probably shouldn't be necessary to do a lot of weird and 
wonderful things.

But it's not going to happen.


More information about the Digitalmars-d mailing list