logoalt Hacker News

chamomeallast Monday at 10:49 AM0 repliesview on HN

For me macros are a power user tool that are useful in libraries to seriously upgrade UX of your public functions. Kinda like how crazy complex typescript generics can seriously upgrade the UX of your lib.

It’s hard to explain without explaining a bunch of what a specific library does. But many clojure libraries expose macros that let you interact with them in much more readable/terse ways.

I’m on my phone but a good one to google is core.logic. It exposes a macro to define a “logic function”, which lets you define logical expressions using pattern matching. You can come up with rules that would be many more LOC and less readable as a normal function. You can of course define them as a normal function too, which is useful when the pattern matching doesn’t express the problem well!