3 ms·
I've programmed Lisp code for several years and personally I do find Lisp code harder to read, especially when doing arithmetic. The direct benefit of Lisp syn
by malisper 7y ago
I've programmed Lisp code for several years and personally I do find Lisp code harder to read, especially when doing arithmetic.
The direct benefit of Lisp syntax is that everything is consistent. Arithmetic operators have the same syntax as regular functions. Because all Lisp code has a consistent structure, that makes it easy to do some really neat things. For example, it isn't hard to write a program that takes Lisp code as input and processes it in some way.
This is the reason why you see so many people write a toy Lisp interpreter. It's really easy to write code to evaluate Lisp code because all Lisp code has an identical structure.
As a Lisp programmer, this benefit emerges in the form of macros. Macros run at compile time, take some Lisp code as input, and spit out new Lisp code as output. The new lisp code is then substituted for the old one.You can think of macros as a very small user-defined compiler. These let you build all sorts of language constructs that you couldn't build in other programming languages. For example, you can add pattern matching to a Lisp with macros. The macro would take a list of patterns and corresponding expressions as input and spit out some code that checks for the patterns and runs the corresponding expressions if the pattern matches.
- hope-striker 7y ago> These let you build all sorts of language constructs that you couldn't build in other programming languages. Many languages (e.g. Rust[0]) let you write procedural macros, even if their grammar is much more complex than that of a Lisp. Is there some technical advantage to Lisp macros over macro processors in other languages (ignoring string-based ones like the CPP), or do all the benefits lie in the massively improved ergonomics of writing macros? (Note that Rust also has simpler hygienic macros, but they're not expressive enough for many things.) [0]: https://doc.rust-lang.org/reference/procedural-macros.html https://doc.rust-lang.org/reference/procedural-macros.html
- roenxi 7y agoYou've pretty much covered it; lisps are better at macros than any language with complicated syntax. Most of the flow control in a lisp (for, while, if, etc, etc) can be implemented with macros. It isn't often a program needs a new form of flow control but when you need it it is there as an option and a lisp will do it better than the competition. If Rust can do threading macros then it probably has enough of the power that it isn't missing out. Still going to be a bit cumbersome. Lisps give you the option that flow control can be implemented in a library. None of the old-school popular languages manage that.