January 2020
Intermediate to advanced
532 pages
13h 31m
English
Throughout this section, we have been focusing on code generation techniques. The premise is that we can easily add a new function that works just like an existing one but a little differently. In practice, code generation is not the only option we have on hand.
Let's continue our discussion with the same example. As we recall, we wanted to add the warning! and error! functions after defining the logic for info!. If we take a step back, we can generalize the info! function and make it handle different logging levels. This can be done as follows:
function logme!(level, label, logger::Logger, args...) if logger.level <= level let io = logger.handle print(io, trunc(now(), Dates.Second), label) ...
Read now
Unlock full access