4 ms·
Norvig nailed it - instead of being sissy about macros altogether the mainstream languages must rather enforce a certain discipline. And the rules for the macro
by sklogic 10y ago
Norvig nailed it - instead of being sissy about macros altogether the mainstream languages must rather enforce a certain discipline. And the rules for the macros done right are very simple and well known.
- jeffreyrogers 10y agoHonestly, I don't get the fuss about macros. I haven't seen many (any?) use cases for them, where they don't make the code harder to understand while doing something that isn't already straightforward in the base language.
- sklogic 10y ago> Honestly, I don't get the fuss about macros. DSLs are an ultimate solution. And DSLs are best implemented with macros. > where they don't make the code harder to understand Macros are there to make code easier to understand. I just explained it in detail elsewhere: https://news.ycombinator.com/item?id=11705170 https://news.ycombinator.com/item?id=11705170
- jeffreyrogers 10y agoYes, I get theory, but I haven't seen much use for them in practice.
- sklogic 10y agoIt puzzles me too, that people are not using the most powerful development technique. I cannot imagine not using macros for pretty much everything I do.
- wry_discontent 10y agoI've written a handful of Clojure and Emacs Lisp, but I don't get macros. How is a macro different than passing a quoted list to a function? Maybe I just need to start slinging more lisp, but I don't see how they're particularly different from functions.
- sklogic 10y ago> How is a macro different than passing a quoted list to a function? Macro is a function that is executed in compile time. Think of it as a way of extending your compiler with new functionality. For example, your language does not have support for pattern matching originally. It's not a problem - you can define a macro that adds such a functionality to a language. You cannot do it with functions - it must be compiled and optimised before execution, and functions cannot introduce new identifiers into a scope. Another simple example would be something like list comprehensions - also introducing variables and also requiring optimisations in compile time. And at extreme level, macros can be used to turn your host language into something totally different. Not just add few new features, but turn it into another language. Lisp can become an ML or Haskell, or Prolog, or Java, or whatever else you can imagine. Macros can change syntax, can implement new semantics. None of it can be done with just functions.