• Skip to main content
  • Skip to footer

PurelyFunctional.tv

  • Learn Clojure
  • About
  • 🛒 Cart
  • Log in

Learn how to extend Clojure using macros

Have you ever wanted a language that adapts to your software? Have you ever wanted to eliminate boilerplate? What about extend the syntax without changing the compiler? Those are what macros let you do.

If you've ever wanted to learn Clojure macros, this course is the place to start. This course jumps right into macros with gusto. It starts with the key to understanding macros, takes you through the implementation of 6 progressively more complex macros, and finishes with the three reasons you need macros.

Beginning with Clojure Macros

Updated February 26, 2021

Want this course?

Online License

$48
Get this course
--
Watch Online
Lifetime Access
For an individual
Buy for $48

Love it or leave it guarantee

If you don't learn as much from this course as you thought, just ask for a refund within 30 days and I'll give you your money back.

Video time: 01h38m
0 / 11
0 / 11

Lessons

5 min Free

1. The key to understanding macros

Do you know the key to really understanding macros? This lesson explains it. It's simpler than you think.

11 min Free

2. Writing our first macro

We jump right in and start coding a simple macro, discovering the sigils we need along the way.

2 min

3. How to tackle difficult macros

Before we dive into our more complex macros, we equip ourselves with a powerful technique that focuses our mental powers on the data transformation at the heart of macros.

6 min

4. Understanding macroexpansion

We need one last tool before we begin our exploration. In order to debug our macros, we need to see what code they are outputting. There are three levels of macroexpansion to learn.

6 min

5. Macro example: when

Clojure's built-in when is a macro that expands into if. Let's write a version ourselves.

6 min

6. Macro example: while

Clojure's while loop is also a macro. Let's make one ourselves!

12 min

7. Macro example: regex

Let's build an interesting macro to simulate regular expression features of Perl and Ruby: automatically binding locals to the match and groups.

19 min

8. Macro example: with-open

One of the more interesting uses of macros is to make with- macros. These bind locals but also do something with them at the end. Let's build with-open.

13 min

9. Macro example: mf

This is an experimental macro that I came up with. It makes a function that "wraps" a macro so that it can be used at runtime.

4 min

10. How to know when you need a macro

People say you shouldn't write a macro unless you need one. I don't know if that's true (it's controversial in the Lisp world). But how do you know you need one?

14 min

11. A deeper explanation of with-open

Do you understand the pattern of using helper functions within a macro and how it can make your macro more useful and easier to understand?

Extra Resources

Clojure Macro Patterns Reference

We tend to code using patterns that we repeat a lot. Learning these patterns can help you level up your macro skills very quickly. This reference sheet contains six annotated patterns that Clojure programmers use all the time.

Clojure Macro Sigils Reference

Have you ever wondered what the symbols in Clojure macros do? I’m talking about `, ~, ~@, etc. This handy reference sheet tells you what they all do, when to use it, and shows examples. Never get lost in a macro again!

Clojure Macroexpand Reference

When we’re developing macros, it really helps to be able to see what code it will output. Fortunately, Clojure comes with three built-in functions for doing just that. They are so useful for debugging. This reference sheet shows what each one does. It also includes how to access macroexpansion in the three most popular Clojure IDEs.

Footer CTA

Level up your Clojure skills

The PurelyFunctional.tv Newsletter is a weekly email that helps you improve your Clojure skills through challenges, tips, and news.

Enter your email address to receive emails about Clojure and Functional Programming. These include the weekly newsletter and occasional offers. You can unsubscribe any time.

Copyright © 2021 LispCast and Eric Normand