Hasty Briefsbeta

Bilingual

When You Get to Be Smart Writing a Macro

a year ago
  • #Macros
  • #Debugging
  • #Clojure
  • Day-to-day programming is often straightforward, but finding smart solutions is rare.
  • The author uses 'hashp' for debugging, which is a better alternative to 'println'.
  • The 'hashp' macro returns the original value, is concise, and shows the original form.
  • Adding 'hashp' to a thread-first macro causes syntax errors due to reader tag expansion.
  • A custom macro 'p->' is created to work within threading macros, but it requires separate macros for different threading styles.
  • A smarter solution is devised using a probe to detect threading context (-> or ->>) dynamically.
  • The new solution works seamlessly in all contexts: normal, thread-first, and thread-last.
  • The enhanced 'hashp' is now part of Clojure+.