Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread WraithGlade via Digitalmars-d-learn
Hello everyone! This is my first post in these forums. D is an interesting language (basically a saner C++, which is a nice prospect because I've used C++ working in the game industry in the past) and I've been considering using it and may still do so. However, there is a very basic debuggin

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread monkyyy via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: I want to just be able to write this: ``` show!(1 + 2) ``` ```d void show(string s)(){ auto res=mixin(s); writeln(s,"==",res); } show!"1+2"; ```

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: Basically, I want there to be a way to print both an expression and its value but to only have to write the expression once (which also aids refactoring). Such a feature is extremely useful for faster print-based debugging. Thus,

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 8 September 2024 at 23:01:22 UTC, monkyyy wrote: On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: I want to just be able to write this: ``` show!(1 + 2) ``` ```d void show(string s)(){ auto res=mixin(s); writeln(s,"==",res); } show!"1+2"; ``` This works for `s

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 00:34:03 UTC, Paul Backus wrote: The only way is that a challenge? void main() { import std.stdio; mixin(show!"1 + 2"); // 1 + 2 == 3 const int x = 1 + 2; mixin(show!"x"); // x == 3 } ``` idk why you calling it a macro, im pretty sure d isnt