News for hackers. Stuff that matters.
Re:Implementing Rust's dbg! in Python by CJefferson on Friday December 11, 2020 @02:30PM (#25389713)
After I saw this in Rust, I had to implement it in C++:

    #include <iostream>
    #include <string>

    template<typename T>
    T print_dbg(T val, std::string exp, std::string file, int line) 
    {
        std::cerr << exp << " = " << val << " @ " << file << ":" << line << "\n";
        return val;
    }

    #define dbg(x) print_dbg(x,#x,__FILE__,__LINE__)
Re:Implementing Rust's dbg! in Python by petschge on Friday December 11, 2020 @07:37PM (#25393804)
Close. Applying that to

    double c = dbg(dbg(a) + dbg(b));
gives

    a = 1 @ debug.cxx:16
    b = 2 @ debug.cxx:16
    dbg(a) + dbg(b) = 3 @ debug.cxx:16
which has extra dbg()s on the third line.

If I could I would probably want to write

    double dbg(c) = dbg(a) + dbg(b);
but that of course doesn't work.