39 ms·
> yet the best macro systems in other languages are copies of what lisp has figured out so far. These are going to be controversial assertions in a Lisp thread
by neutronicus 6y ago
> yet the best macro systems in other languages are copies of what lisp has figured out so far.
These are going to be controversial assertions in a Lisp thread, but I believe
1. C++ Templates + Concepts is a good Macro facility
2. Most of what makes it good is not borrowed from Common Lisp
On the other hand, I agree strongly with this assertion:
> Scripting languages gain much of their leverage from nested hash tables.
- Jtsummers 6y agoI've been pondering this comment, and I'm not sure I agree that C++ Templates + Concepts are really equivalent to Lisp macros. They're about enabling generic programming with type constraints (when you add concepts, in particular). This seems more akin to Common Lisp's defgeneric and defmethod, where you can specialize your implementation based on the type. Like, assuming some class hierarchy of foo (base) -> bar -> baz: (defgeneric do-something (object)) (defmethod do-something ((object foo)) (something every foo can do)) ;; bar is the same as foo (defmethod do-something ((object baz)) (something only bazzes should do)) Templates and concepts are certainly a powerful tool, and I personally like them (as I've come back to C++ after a long break). But macros let you do something else entirely. You can create entirely new syntactic structures, or modify existing functions (see Norvig's PAIP, chapter 9, where macros are used to memoize recursive functions), or any number of other things.
- neutronicus 6y ago> I'm not sure I agree that C++ Templates + Concepts are really equivalent to Lisp macros. I think I said as much in my comment. > This seems more akin to Common Lisp's defgeneric and defmethod Except that Templates are statically dispatched and type-checked. But also one can perform meaningful compile-time computation with them - I have used this in anger to implement stencils and iteration logic for partial differential equation solvers in 1-3 dimensions so I can say from experience that it is not a mere curiosity. And I don't think that CLOS really has any analog for the techniques used to implement std::tuple. > But macros let you do something else entirely. You can create entirely new syntactic structures, or modify existing functions (see Norvig's PAIP, chapter 9, where macros are used to memoize recursive functions), or any number of other things. I think the thrust of my comment is that Lisp programmers identify this type-blind AST-mapping functionality as the core of "a Macro System," while users of other languages (with more syntax to begin with) see this as somewhat secondary to the goal of type-checked compile-time computation.
- oalae5niMiel7qu 6y agoIf C++ had a good macro system, the Qt library wouldn't need the "moc" preprocessor to implement its "slots" abstraction. Templates aren't powerful enough to fill that role, even when you add Concepts to them.
- neutronicus 6y agoMy understanding is that moc is no longer necessary, but sticks around for legacy compatibility, but I may be wrong.