2 ms·
> Yes, it’s possible to concoct the weirdest stuff in Lisp, but that would probably be bad code. Some macros might take time to learn, but unlike Haskell where
by lmm 5y ago
> Yes, it’s possible to concoct the weirdest stuff in Lisp, but that would probably be bad code. Some macros might take time to learn, but unlike Haskell where you need to know monads to be productive, you do not need to know how to author macros to read and write most Lisp.
You need to know what the macros a given codebase uses do if you want to work in that codebase. This is actually a worse situation than in Haskell, where if you're comfortable with monads in general you can probably be productive in a given codebase without knowing about the specifics of the monads that codebase is using.
- reikonomusha 5y agoIt’s not “actually” a worse situation except in some pathological academic sense. The point of a macro is to make some idea clearer to understand by way of syntax. If it’s not doing that, it’s probably a bad macro.
- lmm 5y agoIf you restrict yourself to a reasonable-to-understand subset of possible macros - such as those that could be expressed as monads in Haskell - then a reader that knows that you've so restricted yourself can work in your codebase without understanding all your macros (as long as you don't have any bugs in your macro implementations). But in that case why use a language with macros?
- aidenn0 5y agoYou can teach someone to use the built-in loop macro without using the term "macro." It's far more hairy and complicated then any non built-in macro you will encounter in the wild. Literally the only time I worry about macro vs special operator vs function is when doing higher order programming, which is less common in lisp than Haskell
- lmm 5y agoYou can teach someone to use a fixed set of macros. But again, in that case why use a language with macro features? If you're never going to use a non-built-in macro with the complexity of the built-in macros, why does the language need this complex macro system rather than a set of built-in keywords and a simpler extension system?
- aidenn0 5y ago> You can teach someone to use a fixed set of macros. But again, in that case why use a language with macro features? Because sometimes writing a simple macro makes it easier to write (and read) other code. > If you're never going to use a non-built-in macro with the complexity of the built-in macros, why does the language need this complex macro system rather than a set of built-in keywords and a simpler extension system? There's a lot to unpack here. A good lisp developer will very rarely need to write a macro that approaches the complexity of the loop macro. Firstly, that's not never. Being able to write a hairy macro is more like an air-bag than power windows. You're glad to have it when you need it, but you mostly forget its there the rest of the time. Secondly the same macro system that lets you write something like loop also lets you write simpler macros that make code both easier to read and harder to write incorrectly. Lisp does not have a "complex" macro system. It has one of the simplest extension systems of any language I've used that has an extension system. There are also plenty of people who think loop is too complicated and too inflexible and so avoid it. Finally everything you said about macros and loop can be applied to other languages and the standard library. If nobody's going to write anything as complex as printf(), why does C need variadic functions? If nobody's going to write anything as complex as itertools, why does python need higher-order functions and generators? I don't actually see the extensibility of lisp as its "killer feature" but I definitely see it as a net positive, while a lot of people seem to see it as a net negative. I blame books like "Let Over Lambda" which are more to be seen as examples of what you can do rather than what you should do. There's lots of things to hate about C, but the fact that you can do: enum { TRUE = 0, FALSE=1 }; is not one of them. There's plenty to hate about lisp, but the fact that it's possible to write bad macros is not one of them.
- lmm 5y ago
- Zababa 5y ago> The point of a macro is to make some idea clearer to understand by way of syntax. The question I think is clearer for who? Macros, as all abstractions, seem to be a way to make the expert faster at the expense of the beginner. Lisp is probably better at avoiding accidental complexity coming with it, but I don't think it avoids complexity entirely.
- kazinator 5y agoThe way to settle this, at least for a given macro or macros, is to bring the expert and beginner together, and have both of them examine the macro calls, their documentation, and a version of the code in which the macro calls have been replaced by their hand-written expansions.