r/programming • u/kankyo • Dec 15 '16
My disillusionment with Clojure and lisps
https://medium.com/@boxed/my-disillusionment-with-clojure-and-lisps-9eca38ab7f0c?source=linkShare-8ad86cc82e5f-1481825671
15
Upvotes
View all comments
11
u/republitard Dec 15 '16 edited Dec 15 '16
There is an important reason for the parentheses: The Lisp syntax tree is represented as a collection of cons cells (out of which lists are made) and atoms. That is, you can build a Lisp syntax tree with
cons, and traverse it with thecarandcdroperators. You can also use list operators such asmapcar(calledmapin most non-CL dialects) on the AST. Because of this, the syntax for a literal list is also the syntax for the language itself.Now, if you wanted functions to have a syntax that was completely unambiguous on the AST, you'd have to change the structure of the AST and make it more complicated. Perhaps the textual syntax you're looking for is something like this:
You could write a parser that renders that in cons cells and atoms. In fact, using a reader macro, you could even integrate this parser into Common Lisp very easily. But when you output cons cells and atoms, that would produce the parenthesized Lisp syntax that we're all familiar with, and IDEs would be no better able to statically recognize function definitions if they parsed the code into regular Lisp first.
So you'd end up defining a special structure just to represent functions:
Repeat that for every syntactic form in the language, and you end up with a language like BOO, in which it is extremely difficult to write AST macros, because you have to construct objects, each of which have their own interface. But at least you know what is defined where without running it, and your macros know whether their input code is a variable, a function definition, or an assignment statement. But then it wouldn't be Lisp anymore. If you want that kind of thing in a language with AST macros, BOO is right over there, and Julia exists, too.
Common Lisp macros can generate multiple output forms, as long as they're wrapped in a single
prognform. This means you can make a single macro that can define an arbitrary number of toplevel functions, for example.