5 ms·
One example that I feel most devs can appreciate is the elimination of "boilerplate" code. How often in your non-macro language do you find yourself repeating t
by pepper_sauce 8y ago
One example that I feel most devs can appreciate is the elimination of "boilerplate" code. How often in your non-macro language do you find yourself repeating the same lines of code with minute differences?
Think about JavaScript before and after destructuring was implemented. How many lines of code and mental effort are saved!
In Common Lisp this is just a macro, DESTRUCTURING-BIND (http://www.lispworks.com/documentation/HyperSpec/Body/m_destru.htm http://www.lispworks.com/documentation/HyperSpec/Body/m_dest...). Not a fan of the syntax? Just write a macro to modify how you use it.
Macros allow you the programmer to do similar things, but with anything you want. You don't have to wait for a language committee to agree on something, and then a third party to write a convoluted pre-processing system to 'transpile' the code to work. It's built into the language.
- pepper_sauce 8y agoReally though, I felt similarly to OP until I read On Lisp[0] and Let Over Lambda[1]. They are chock full of explicit examples. You can only learn so much from StackOverflow questions and Quora answers. I also hear good things about Paradigms of AI Programming, but I haven't read it yet. From Peter Norvig's retro on the book[2], here are the lessons in it which involve macros: Design patterns can be used informally, or can be abstracted into a formal function, macro, or data type (often involving higher-order functions). [p. 177] We can write a compiler as a set of macros. [p. 277] If you can understand how to write and when to use once-only, then you truly understand macros [p. 853] A word to the wise: don't get carried away with macros [p. 855] [0] http://www.paulgraham.com/onlisp.html http://www.paulgraham.com/onlisp.html [1] https://letoverlambda.com/index.cl/toc https://letoverlambda.com/index.cl/toc [2] https://norvig.com/Lisp-retro.html https://norvig.com/Lisp-retro.html