Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15. More macros and DSLs > Domain-specific languages - Pg. 383

Domain-specific languages 383 Having said this, although writing macros is a common thing to do in a Clojure program, it isn't often the case that a macro generates another macro. You'll probably do it only a handful of times in your career. Combined with the other usages you've seen, such as moving computation to compile time and intentional symbol capture-- the few times when you do need macros to abstract patterns out of macros them- selves--writing macros to generate macros can lead to a solution that would be diffi- cult without the technique. The second reason, and the more commonly useful one, for knowing this concept is to drive home the process of macro expansion, quoting, and unquoting. If you can understand and write macros that generate macros, then you'll have no trouble writ- ing simpler ones. With these topics about macro writing out of the way, we're ready to move on to a couple of examples. In the next section, we'll look at using macros to create domain- specific languages ( DSL s). 15.2 Domain-specific languages We're now going to look at explicitly doing something we've been doing implicitly so far. In several chapters, we've written macros that appear to add features to the Clojure language itself. An example is def-worker , which allowed us to create func- tions that can run on multiple worker machines in a cluster. We also created a simple object system with most of the semantics of regular object-oriented languages. We cre-