3 ms·
Intro To Clojure Macros
- chc 13y agoLispers to novices: "Macros are the most powerful way to manipulate the syntax of your language. Macros make it possible to completely modify your language to match your domain." Lispers to other Lispers: "Don't use macros."
- JackMorgan 13y agoI've heard this advice, like how they can't be called inside maps, etc, and I politely disagree. I think the power they represent should not be simply tossed out because they are harder to use. At least right now, I'll take the power along with the increased complexity for my side projects until such time as I see they are not worth it. (I'm not writing them into any production code, for what's it's worth)
- fredyr 13y agoOh, lispers use macros all the time. It's just that you're not going to solve every problem by writing a new one. For example in Clojure, or, and, fn and cond are macros you typically use all the time.
- JackMorgan 13y agoThis I completely agree with. I want to learn them for the same reason Doug Hoyte suggests: "The conventional wisdom surrounding macros is to use them only when necessary because they can be difficult to understand, contain extremely subtle bugs, and limit you in possibly surprising ways if you think of everything as functions. These aren't defects in the lisp macro system itself but instead are traits of macro programming in general. As with any technology, the more powerful the tool, the more ways there are to misuse it. And, as far as programming constructs go, lisp macros are the most powerful tool. An interesting parallel to learning macros in lisp is that of learning pointers in the C programming language. Most beginning C programmers are able to quickly pick up most of the language. Functions, types, variables, arithmetic expressions: all have parallels in previous intellectual experiences beginners might have had, from elementary school maths to experimenting with simpler programming languages. But most novice C programmers hit a brick wall when they encounter pointers. Pointers are second nature to experienced C programmers, most of whom consider their complete understanding necessary for the proper use of C. Because pointers are so fundamental, most experienced C programmers would not advise limits on their use for stylistic or learning purposes. Despite this, many C novices feel pointers are an unnecessary complication and avoid their use, resulting in the FORTRAN in any language symptom where valuable language features are neglected. The disease is ignorance of the language's features, not poor programming style."
- lispm 13y agoIt's exactly the opposite. SICP uses no macros. AMOP does.
- cgag 13y agoI generally hear the advice write everything you can as functions, then use macros for making things easier to express. Locking functionality up in macros is probably bad, making things convenient with them is fine.