4 ms·
It's not that difficult. Lisp makes it easier, because one can look at code. For example look at this built-in Lisp macro example, which iterates from 0 to 9 a
by lispm 2y ago
It's not that difficult. Lisp makes it easier, because one can look at code.
For example look at this built-in Lisp macro example, which iterates from 0 to 9 and writes the numbers.
CL-USER> (dotimes (i 10)
(write i))
0123456789
NIL
Common Lisp has tools like a pretty printer for code (-> PPRINT) and a tool for expanding a macro form:
CL-USER> (let ((*print-right-margin* 30))
(pprint (macroexpand '(dotimes (i 10) (write i)))))
(BLOCK NIL
(LET ((I 0))
(DECLARE
(TYPE UNSIGNED-BYTE I))
(DECLARE (IGNORABLE I))
(TAGBODY
(GO #:G267)
#:G266
(TAGBODY (WRITE I))
(PSETQ I (1+ I))
#:G267
(UNLESS (>= I 10)
(GO #:G266))
(RETURN-FROM NIL
(PROGN NIL)))))
From above one can see that the code gets transformed in very low-level Lisp code, with a GO operator (-> a GoTo). It's a low-level loop expressed by loop made from a simple goto operator. One can look at the code and try to figure out what it is doing. One is not guessing what the expanded code looks like, one can generate the expanded code and see what it looks like.
- ativzzz 2y agoThat's neat, better than ruby in that regard. Still hate the () syntax especially when you have a bunch of nested functions, I bet you get used to it though
- pjlegato 2y agoMost use an IDE such as Emacs (paredit-mode and rainbow-parens) that handles automatic paren matching for you, so it's really a non-issue after the first week. The editor takes care of indentation, matching (so you don't have any dangling parens ever), and optionally colors matching pairs in the same color so you can easily tell what level they're at. This is a fairly typical look: https://ericscrivner.me/wp-content/uploads/2015/06/rainbow-delimiters.png https://ericscrivner.me/wp-content/uploads/2015/06/rainbow-d...
- iLemming 2y agoAfter a few years, I turned off rainbow-parens-mode indefinitely. I realized that I no longer see parentheses and instead I see the structure and order, or in the case of badly-written code - chaos and anarchy. It is sad that the usual first reaction of people seeing Lisp code is distaste. I myself wasted years of my life because of that. I had many opportunities to learn Lisp, but I dismissed them multiple times until I tried Clojurescript. Stupid me.
- deleted 2y ago[deleted]
- iLemming 2y ago> especially when you have a bunch of nested functions In non-lispy langs like JS, deeply nested statements could lead to callback hell or pyramid of doom, making the code harder to read, understand, and debug. In Lisps, nested expressions are common and idiomatic due to the Lisp's code-as-data philosophy. In Lisps, code is composed of expressions that can be composed together, with each expression potentially being an evaluation of other sub-expressions. This doesn't lead to a pyramid of doom, since the emphasis often is on data transformation rather than orchestration of side effects. Nested expressions allow you to build complex behaviors from simpler ones in a very direct and composable manner, thereby making code concise and easy to reason about. Deeply nested statements in Javascript often hurt readability and maintainability, while nested expressions e.g., in Clojure typically enhance them due to their emphasis on code/data composition and transformation. It is a difference of chaotic complexity versus structured and intended composition.