Hello!
It is very common pattern to include parts of code which are used for
specific purposes - for example debugging, logging, etc. While these parts
can be used when developing code, they can be removed from finished
application. One way is to comment these parts out, when we are done.
Since commenting can be tedious and error-prone, it makes sense to make a
macro for this:
(def *debug* true) ; true/false
(defmacro debug [& body]
(if *debug*
`(do [EMAIL PROTECTED])))
(defn myfn [x]
(debug
(println "Print some debug info...")
(print "x = ") (prn x))
(* 2 x))
(myfn 5)
To extend this idea little further, lets define "code sections":
(def *section-tags* {:debug true :log0 true :log1 false})
(defmacro section [tag & body]
(if (*section-tags* tag)
`(do [EMAIL PROTECTED])))
(defn myfn [x]
(section :debug
(println "debugging info...")
(print "x = ") (prn x))
(section :log0
(println "logging info..."))
(section :log1
(println "detailed logging info..."))
(* 2 x))
(myfn 10)
Latest addition for libs to boot.clj also has this pattern, when using
*loading-verbosely* flag.
Any comments welcome, Frantisek
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---