Mastering Clojure Macros
Write Cleaner, Faster, Smarter Code
by: Colin Jones
Published | 2014-08-20 |
---|---|
Internal code | cjclojure |
Print status | In Print |
Pages | 120 |
User level | Intermediate |
Keywords | clojure, lisp, macros, metaprogramming, jvm, jvm languages |
Related titles | Programming Clojure by Stuart Halloway and Aaron Bedra is a great example of a book people might read before reading Clojure Macros. - Web Development with Clojure |
ISBN | 9781941222225 |
Other ISBN |
Channel epub: 9781680503920 Channel PDF: 9781680503937 Kindle: 9781941222317 Safari: 9781941222768 Kindle: 9781941222317 |
BISACs | COM051100 COMPUTERS / Programming Languages / LISPCOM051440 COMPUTERS / Software Development & Engineering / ToolsCOM051440 COMPUTERS / Software Development & Engineering / Tools |
Highlight
Level up your skills by taking advantage of Clojure’s powerful macro system. Macros make hard things possible and normal things easy. They can be tricky to use, and this book will help you deftly navigate the terrain. You’ll discover how to write straightforward code that avoids duplication and clarifies your intentions. You’ll learn how and why to write macros. You’ll learn to recognize situations when using a macro would (and wouldn’t!) be helpful. And you’ll use macros to remove unnecessary code and build new language features.
Description
Clojure offers some sharp tools in its toolbox, and one of the sharpest is its macro system. This book will help you write macros using Clojure, and more importantly, recognize when you should be using macros in the first place.
The Lisp “code-as-data” philosophy gives tremendous advantages to macro authors and users. You can use macros to evaluate code in other contexts, move computations to compile time, and create beautiful API layers. You don’t need to wait on the Clojure language itself to add new features, you’ll learn how to implement even the lowest-level features as macros. You’ll step through representative samples of how to use macros in production libraries and applications, find clear details on how to construct macros, and learn pointers to avoid obstacles that often trip up macro amateurs.
Clojure macros are more straightforward to use than metaprogramming features in many other languages, but they’re different enough from normal programming to present challenges of their own. Mastering Clojure Macros examines some of these issues, along with alternatives to macros where they exist.
By the time you finish this book, you’ll be thinking like a macro professional.
Contents and Extracts
- Acknowledgments
- Introduction
- Why Clojure?
- Why Macros?
- Metaprogramming in Non-Lisps
- Who Is This Book For?
- What’s in This Book?
- How to Read This Book
- Online Resources
- Build a Solid Foundation
- Code Is Data
- Transforming Code
- Evaluating Your First Macro
- Macroexpansion
- Advance Your Macro Techniques excerpt
- Syntax-Quoting and Unquoting
- Approaching Hygiene with the Gensym
- Secret Macro Voodoo
- Use Your Powers Wisely
- Macros Aren’t Values
- Macros Can Be Contagious
- Macros Can Be Tricky to Get Right
- Evaluate Code in Context
- Dynamic Bindings
- Evaluating (or Not) in Time and Place
- Rescuing Errors
- Cleaning Up Resources
- Speed Up Your Systems excerpt
- Benchmarking Your Code
- Hiding Performance Optimizations
- Moving Execution to Compile Time
- Build APIs That Say Just What They Mean
- Compojure
- Clojure Koans
- Decoupling Macros from Functions
- Bend Control Flow to Your Will
- Loops and Loops and Loops and…
- Turning Expressions Inside Out with Threading Macros
- Delimited Continuations
- Implement New Language Features
- Implementing Pattern Matching
- Error Handling in Macros
- Code-Walking Macros
- Macros Are [Not] Magic