On 04/11/2011 11:27 PM, bearophile wrote:
 From what I am seeing, in a D2 program if I have many (tens or more) pure functions that 
call to each other, and I want to add (or activate) a printf/writeln inside one (or few) 
of those functions to debug it, I may need to temporarily comment out the 
"pure" attribute of many functions (because printing can't be allowed in pure 
functions).

As more and more D2 functions become pure in my code and in Phobos, something 
like a -disablepure compiler switch (and printf/writeln inside debug{}) may 
allow more handy debugging with prints (if the purity is well managed by the 
compiler then I think disabling the pure attributes doesn't change the program 
output).

Similar to Adam's idea, I'd like a debug-only func, maybe called 'note' (because 'log' is too ambiguous). 'log' could do the same thing as writeln;
or even better:

    void f (int n) {
        note(n*n);
        ...
    }
    f(3); // writes: "n*n: 9\n"

Meaning, no need to explicitely type:

        note("n*n: ", n*n);

This indeed requires some compiler magic. For simplicity, note could be non-variadic (--> one note per line, both in code and on output).

In any case, the point is for note to be considered pure, because debug-output-only. And would not be compiled in -release mode. (nice side-effect: debug output statements can then stay in code as are)

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to