This code "does the trick" (except in Playground) :

https://play.golang.org/p/kJAfNFZUev

$ go run macro.go 
dump(a + b) = 14
dump(b * a) = 40

$ go build -o macro
$ ./macro 
dump(a + b) = 14
dump(b * a) = 40

Read current stacktrace, extract source file path, read source file, 
extract textual (uncompiled) expression.

Disclaimer : I have no idea what I'm talking about

On Friday, July 22, 2016 at 2:28:19 PM UTC+2, sq...@google.com wrote:
>
> I've used this macro or some variant thereof in C/C++ for years:
>
>   #define dump(x) printf("%s %d: %s = %d\n", __func__, __LINE__, #x, 
> (int)(x))
>
> The "#x" is the really useful part that lets you print the original 
> expression. For example, if int a = 4 and int b = 10:
>
>   dump(a + b);  // Prints "a + b = 14"
>
> Is there a way to do this in Go? 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to