[racket] avoiding unnecessary work when using `log-debug` et al
Is there a reason not to redefine `log-debug` et al as macros that evaluate their arguments lazily?
Sort of like this;
(if ((current-logging-level) . is-equal-or-above? . 'debug)
(log-debug arg ...)
(void))
Because I find that my use of these functions often looks like this:
(log-debug "Value = ~a" (expensive-operation-for-logging-purposes))
The problem is that when I change to a lower logging level, the (expensive-operation) is still evaluated.
I asked a similar question about hash-ref! not long ago. The answer was that you can get lazy evaluation by wrapping the default argument in a lambda, like so:
(hash-ref! hashtable key (λ () (expression-that-produces-value)))
But it seems there's no equivalent idiom for `log-debug` et al.