4 ms·
> It's the other way around. Lisp macros allow to eliminate boilerplate and produce clearer code. This is obvious to any lisper. I don't have any particular ex
by jcranmer 7y ago
> It's the other way around. Lisp macros allow to eliminate boilerplate and produce clearer code. This is obvious to any lisper.
I don't have any particular experience with Lisp macros, but my experience with the closest equivalent in every language I've experienced them in is very different from your experience. For the person who wrote the system, it's a clean and expressive way that eliminates boilerplate. For everybody else, though, it's an underdocumented mess of magic incantations with some mental notes of "don't try to combine these things together, it will blow up," and if you ever have to debug a problem in the macro itself, you're going to find it to be a royal pain.
- flavio81 7y ago>I don't have any particular experience with Lisp macros, but my experience with the closest equivalent in every language I've experienced them in is very different from your experience. Yes, because the way metaprogramming is achieved in other languages is very different than the way it is done in Lisp, thanks to s-expressions. >and if you ever have to debug a problem in the macro itself, you're going to find it to be a royal pain. Yes, because you're not dealing with Lisp macros. If i'm looking at a Lisp source code, and there's a macro invocation, and I want to see what this macro is going to do to the code,i just press a key, and I can immediately visualize, in-place, how the source code gets transformed. A big part of the standard library of Common Lisp itself is implemented as macros too, it's no big deal. Dealing with others' macros has no particular difficulty in Lisp; or in any case, no additional difficulty to dealing with others' functions.
- jcranmer 7y agoFrom what I understand, the Rust procedural macro system should basically be similar in structure to Lisp macros, much closer than any other language I've used. It still has all of the aforementioned problems, in my experience.
- slaymaker1907 7y agoRacket (which admittedly is a particular Lisp) has a very useful tool which lets you view each basically debug macro expansion by viewing each code transformation. This tool is even built into Dr. Racket so it doesn’t need any complex setup. I’ve written both procedural Rust macros and Racket. Racket is far easier to debug and write macros compared to Rust despite their macros having similar features (in particular source locations and doing macro evaluation as a compilation step rather than at runtime).
- darkpuma 7y agoMacros are just another form of abstraction, like functions. And like functions, they can be poorly named or poorly designed. Somehow the possibility of suboptimal use is frequently paraded around as an argument against macros, but seldom heard as an objection to functions. (Also, macro systems like Racket's syntax-parse facilitate the creation of macros that fail gracefully with nice error messages.)
- erik_seaberg 7y agoWhen the problem domain needs a novel control structure, and I can't write a macro, I have to try to expand the macro in my head and then you have to read boilerplate and infer what I meant.