Jump to page: 1 2 3
Thread overview
Convenient debug printing
Feb 01, 2019
Per Nordlöw
Feb 01, 2019
Jacob Carlborg
Feb 01, 2019
12345swordy
Feb 01, 2019
Meta
Feb 01, 2019
JN
Feb 01, 2019
Adam D. Ruppe
Feb 01, 2019
jmh530
Feb 02, 2019
Olivier FAURE
Feb 02, 2019
Jacob Carlborg
Feb 02, 2019
Neia Neutuladh
Feb 02, 2019
Dmitry
Feb 02, 2019
Jacob Carlborg
Feb 02, 2019
Neia Neutuladh
Feb 04, 2019
Jacob Carlborg
Feb 02, 2019
Jacob Carlborg
Feb 02, 2019
Rubn
Feb 02, 2019
Per Nordlöw
Feb 02, 2019
Per Nordlöw
Feb 02, 2019
ezneh
Feb 02, 2019
Olivier FAURE
Feb 02, 2019
Olivier FAURE
Feb 02, 2019
Patrick Schluter
Feb 02, 2019
Jacob Carlborg
Feb 02, 2019
Gary Willoughby
Feb 02, 2019
ezneh
Feb 03, 2019
Per Nordlöw
Nov 17, 2019
Robert M. Münch
February 01, 2019
Rust just added a standard macro `dbg` for debug printing

https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#the-dbg-macro

What's the closest match for this macro we can get with D?


I have put together a similar solution at

    https://github.com/nordlow/phobos-next/blob/master/src/dbgio.d#L51

used as

    int x = 42;
    dbg("x: ", x);

printing

    dbgio.d:68: Info: x: 42

but it only works with a cumbersome writeln-syntax.


I also have

    https://github.com/nordlow/phobos-next/blob/master/src/dbgio.d#L12

copied from Wilzbach's effort and used as

    int x = 42;
    int[] y = [42, 43];
    mixin dump!("x", "y");

printing

    dbgio.d:17: Info: x: 42, y: [42, 43]

but, of course, cumbersome in another syntactic way.


Is this as good as it gets in D with regards to syntactic sugarness?
February 01, 2019
On 2019-02-01 16:49, Per Nordlöw wrote:

> Is this as good as it gets in D with regards to syntactic sugarness?

No, not if you want it to print the variable name. Yet another case for AST macros.

-- 
/Jacob Carlborg
February 01, 2019
On Friday, 1 February 2019 at 19:34:30 UTC, Jacob Carlborg wrote:
> On 2019-02-01 16:49, Per Nordlöw wrote:
>
>> Is this as good as it gets in D with regards to syntactic sugarness?
>
> No, not if you want it to print the variable name. Yet another case for AST macros.

I am pretty sure that the universe will freeze-over, before Walter consider AST macros.

-Alex
February 01, 2019
On Friday, 1 February 2019 at 20:32:54 UTC, 12345swordy wrote:
> I am pretty sure that the universe will freeze-over, before Walter consider AST macros.
>
> -Alex

Meaning no offense to Walter, his recent statements on the AST macros makes me think that he is mistaking what Jacob has proposed before (Lisp or Rust-style hygienic AST macros) for C-style text macros (which are, of course, supremely terrible).

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.
February 01, 2019
On Friday, 1 February 2019 at 21:40:29 UTC, Meta wrote:
> C-style text macros (which are, of course, supremely terrible).

What's the difference between C #define and stitching strings with ~ all over the place?
February 01, 2019
On Friday, 1 February 2019 at 21:48:18 UTC, JN wrote:
> What's the difference between C #define and stitching strings with ~ all over the place?

those ~ strings can only be stitched to other strings, not to the rest of the program. mixin operates as complete blocks (it inserts AST nodes, not code per se).

of course you could say the same thing about ast macros lol
February 01, 2019
On Friday, 1 February 2019 at 21:40:29 UTC, Meta wrote:
> [snip]
>
> Meaning no offense to Walter, his recent statements on the AST macros makes me think that he is mistaking what Jacob has proposed before (Lisp or Rust-style hygienic AST macros) for C-style text macros (which are, of course, supremely terrible).
>
> 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.

In general, the rvalue DIP makes pretty clear that Walter and Andrei have a high bar for the quality of a DIP, particularly one that could have a big impact on the language. I don't think the old AST macro DIP is probably up to the standard that would be needed at this point regardless. It would need a re-work and definitely need to be written from the perspective of convincing W&A, which is a pretty high hurdle given their biases.

Two of the interesting things about AST macros to me are 1) that it seems pretty straightforward to implement C++'s metaclass proposal using them, 2) not only could a lot of D's other features like foreach be written in terms of them but a lot of the attributes could too. This could enable a lot of customization, which could be good or bad...
February 02, 2019
On Friday, 1 February 2019 at 15:49:24 UTC, Per Nordlöw wrote:
> Rust just added a standard macro `dbg` for debug printing
>
> https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#the-dbg-macro
>
> What's the closest match for this macro we can get with D?
>
>
> I have put together a similar solution at
>
>     https://github.com/nordlow/phobos-next/blob/master/src/dbgio.d#L51
>
> used as
>
>     int x = 42;
>     dbg("x: ", x);
>
> printing
>
>     dbgio.d:68: Info: x: 42
>
> but it only works with a cumbersome writeln-syntax.
>
>
> I also have
>
>     https://github.com/nordlow/phobos-next/blob/master/src/dbgio.d#L12
>
> copied from Wilzbach's effort and used as
>
>     int x = 42;
>     int[] y = [42, 43];
>     mixin dump!("x", "y");
>
> printing
>
>     dbgio.d:17: Info: x: 42, y: [42, 43]
>
> but, of course, cumbersome in another syntactic way.
>
>
> Is this as good as it gets in D with regards to syntactic sugarness?

import std.stdio;

void dbg(alias a)(string file = __FILE__, int line = __LINE__) {
	writeln( file, "(", line, "): ", __traits(identifier, a), " = ", a );
}

int value = 10;
dbg!value;      // filename.d(12): value = 10


February 02, 2019
On Saturday, 2 February 2019 at 00:06:58 UTC, Rubn wrote:
> void dbg(alias a)(string file = __FILE__, int line = __LINE__) {
> 	writeln( file, "(", line, "): ", __traits(identifier, a), " = ", a );
> }

Nice!

I wasn't aware of `__traits(identifier, a)`. What role does it play here?

Further, can we make this variadic with respect to `alias a`?
February 02, 2019
On Saturday, 2 February 2019 at 00:25:02 UTC, Per Nordlöw wrote:
> I wasn't aware of `__traits(identifier, a)`. What role does it play here?

Ahh, of course, I returns the symbol name as a `string`.
« First   ‹ Prev
1 2 3