Macro example: with-open


#1

Originally published at: https://purelyfunctional.tv/clojure-macros/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.


#2

I had to create an account to say that the first half of this video was great. It was illuminating and a very good description of a macro that is medium in complexity.

However, the second half completely lost me. Why do a function that the macro calls? It’s asserted that it’s a common pattern, but that’s not a reason enough for me.

Secondly, while I understood the function definition itself, how the macro invokes the function is completely opaque. The macro expansion does not help. I was pretty frustrated by the end.

Would it be possible to have a more detailed explanation of why have the macro invoke a function, as well as why this is a common pattern?

Thanks


#3

Hi @srdjan,

Thanks for the question. And sorry if it was frustrating. I rely on questions to help clarify points I need to go deeper into. So this is awesome!

I’m planning to address this question in a video this week.

Thanks
Eric


#4

Hi @srdjan,

I’ve answered your question. It was a great question and fun to go into:

Please ask if you have more!

Eric