Lisp programs don't have parentheses — they are made of nested linked lists. The parentheses only exist in the printed representation — the ASCII serialization — of a Lisp program. They tell the Lisp reader where the nested lists begin and end. Parenthesis are the contour lines in the topographic map of your Lisp program.
The parentheses allow other programs, such as editors, to manipulate the program text as a tree structure. You can use the parenthesis to determine the structure of the Lisp program without needing a complicated parser. You only need to know how to count the opening and closing parentheses to determine the boundaries of expressions in the text of a program. You don't need an IDE or a treesitter process running a language parser in the background to make sense of the lexical structure of the program.
This makes refactoring of a Lisp program easy because the expression boundaries are explicitly marked. Additionally, Lisp expressions do not have a dependency on the context in which they appear — Lisp expressions don't change form when you move them around. Contrast this with, for example, expression sequences in C. In C, in a statement context, expressions are terminated by semicolons, but in an expression context, they are separated by commas. If you move a sequence of expressions in C from statement to expression context, you also have to change the semicolons to commas.
As another example, in C and Java, conditional statements follow
the if … else …
form, but
conditional expressions use the infix ternary ?:
operator, so moving conditionals around may require a substantial
edit. In a language without ternary conditionals, like Go and
Rust, wrapping a subexpression with a conditional may require
large rewrites of the surrounding code.
These days, people use complex IDEs to write and refactor code. But still, you are dependent upon what the IDE provides. A refactoring that is not supported by the IDE has to be done manually. But Lisp just lets you move expressions around as text. No muss, no fuss. You can even use a simple text editor to do it.
Stupid pointless wrong-headed pedanticism. Lisp programs are source code representations, and they contain parentheses. Lisp *processes* may generally not contain parentheses.
ReplyDeletePerhaps you'd be happier reading a different blog.
DeleteMight also point out here that Rust _does_ have a ternary operator, it just spells it "if" (everything is an expression, including if statements). So the following should all be equivalent:
ReplyDeletelisp: (if q t e)
haskell: if q then t else e
rust: if q { t } else { e }
various other languages: q ? t : e (with a special caveat for PHP which managed to get the operator precedence backwards, because of course they did)
I stand corrected. The literature was unclear to me, but on further inspection the if ... else form can be used as both a statement and an expression. Score one for Rust.
DeleteMy computer program doesn’t crash. It is a list of characters. At runtime, it merely stops working, but the characters are intact!
ReplyDelete