August 2014
Intermediate to advanced
120 pages
2h 45m
English
Next we’ll look at an important consequence of macros not being values: macros that take a variable number of arguments can infect their callers, forcing the author to write more macros instead of functions. Let’s take a look at an example and think about the implications for calling code:
| beware/contagious_1.clj | |
| | (require '[clojure.string :as string]) |
| | (defmacro log [& args] |
| | `(println (str "[INFO] " (string/join " : " ~(vec args))))) |
| | |
| | user=> (log "that went well") |
| | ;[INFO] that went well |
| | ;=> nil |
| | user=> (log "item #1 created" "by user #42") |
| | ; [INFO] item #1 created : by user #42 |
| | ;=> nil |
If you recall what you learned in Chapter 2, Advance Your Macro Techniques, you’ll notice that we’re ...
Read now
Unlock full access