by TenDecigrams · 11y ago · 0 comments
I don't understand why this is special?
Why can't you rewrite log.debug to include the check?
func debug(m string) {
if log.isDebugEnabled() {
log.debug(m);
}
}
What makes macros special in this case?Of course, with support for first-class functions, you could do something like:
func debug(produceMessage ()->string) {
if log.isDebugEnabled() {
log.debug(produceMessage());
}
} debug( function(){ return "my expensive log message" })
BTW, if your language is lazily evaluated (like Haskell) then you don't need to do this because arguments will only ve evaluated when they are needed.