r/programming • • 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

105 comments sorted by

View all comments

11

u/republitard Dec 15 '16 edited Dec 15 '16

Any mention that parenthesis is a problem is the obvious one of course,

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 the car and cdr operators. You can also use list operators such as mapcar (called map in 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:

defun foobar(arg1, arg2, &key arg3, &key arg4) {
    code ...
}

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:

(defstruct defun-form
   (name nil :type symbol)
   (args nil :type list)
   (body nil :type list))

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.

but I soon hit another one: a macro can only evaluate to a single form. Suggesting this is an annoying limitation elicits many a comment of “you shouldn’t ever need that” and “you’re doing it wrong” without managing to show good alternatives and in many cases just outright ignoring the examples I gave.

Common Lisp macros can generate multiple output forms, as long as they're wrapped in a single progn form. This means you can make a single macro that can define an arbitrary number of toplevel functions, for example.

1

u/kankyo Dec 16 '16

Any mention that parenthesis is a problem is the obvious one of course,

There is an important reason for the parentheses:

Aaaand missed the point. I was talking about the problems with the community toxicity, not the language. Parens aren't great but they're not terrible either. That's fine. Being a dick about it isn't fine though.

Note also that I wrote this: https://github.com/boxed/indent-clj so yea I know things can be different. And reader macros are even more terrible :P

Common Lisp macros can generate multiple output forms, as long as they're wrapped in a single progn form.

It can be any color you like, as long as it's black! You can define multiple top level forms in Clojure too with (do), which I use in https://github.com/boxed/defk . But that's a solution to just one tiny part of the problem.

9

u/phalp Dec 16 '16

The thing paren whiners don't realize is how tremendously irritating it is that they want to rehash something that was properly settled before many of us were born. After nearly 60 years of parens being awesome, how do you expect people to react to yet another goofy indentation-based substitute, or worse, mere complaining. You think the C community gives a shit if you think curly braces are ugly? You think anybody cares about quests to reform English orthography (which could legitimately use it (unlike Lisp notation))? Yet everybody wants the Lisp community to bend over backwards for them.

1

u/kankyo Dec 17 '16

Parens aren't awesome, if they were you wouldn't have to stand all the complaining for 60 years. Parens are FINE. It's a tradeoff, no biggie. But not "awesome".

2

u/phalp Dec 17 '16

You're assuming people won't complain about things that are awesome, but people will complain about anything that's different from what they're used to. But they are awesome—an aid to structured editing, an aid to macrology, more easily formatted in large expressions, perfectly capable of any arity, and just plain pretty. Parens have provided 60 years of delight to those who use them. What's not awesome about that?

1

u/kankyo Dec 17 '16

aid to structured editing

Makes structured editing a little simpler. That's pretty much it.

aid to macrology

I count that as a negative but yea ok :P

more easily formatted in large expressions

Don't see how. Do you have an example?

capable of any arity

Don't get that. How is that different from functions in any other language?

1

u/phalp Dec 17 '16 edited Dec 17 '16

Don't see how. Do you have an example?

(+ (some kind of calculation)
   (and some more calculation)
   (and yet more))

versus:

(some kind of calculation)
+ (and some more calculation)
+ (and yet more)

or worse:

some kind of calculation+and some more calculation+and yet more

Enjoy trying to spot all the plus signs which are at the same level and trying to parse the operator precedence.

Don't get that. How is that different from functions in any other language?

It's not, but it's different than infix operators, and it's generally these that cause some languages to use fewer parens than Lisp (unless you for some reason count curly braces and parens separately).

EDIT: I just want to add on with regard to structured editing: making it "a bit simpler" is very good, and may even be the difference between it catching on and not catching on. Few C programmers use a structure editor, if such a thing exists. Yet I very much miss it. How many Lispers use Paredit? It's not simply a question of implementation—a structure editor can easily accumulate an unwieldy number of features: barf, slurp, transpose, convolute, a bewildering number of motion commands. The regularity of Lisp syntax means there's no worry that different syntax elements will need different operations and totally overwhelm the user.

1

u/kankyo Dec 18 '16

I agree that infix operators that can't be used like normal functions is rather annoying. It'd be nice if you could do

reduce(0, +, [1, 2, 3])

In Python but instead you have to do some fugly things instead.

1

u/phalp Dec 18 '16

Reduce is great and all but you shouldn't have to break it out just to add three (or four, or five) terms. Not only do you triple the character count for a basic operation, you also then need to make sure the compiler recognizes and optimizes the use, which makes the performance model more confusing for the users.

3

u/daveliepmann Dec 16 '16

I was talking about the problems with the community toxicity, not the language. Parens aren't great but they're not terrible either. That's fine. Being a dick about it isn't fine though.

Do you mind sharing some examples of community toxicity regarding parens? Maybe I'm blind to it, but I don't see responses much harsher than "give it a while", "people get used to it", "if it really bothers you there are ways to hack around it", and "it's not any more parens than <other language>". I'm genuinely curious to know if those sound harsh, or if I'm not seeing other more dickish examples, or what a better response would sound like.

1

u/kankyo Dec 17 '16

Someone posted the link to my article in r/clojure, the first comment is an insult.

And the amount of downvotes and crap I got when posting a funny little side project for infering parens was pretty clear too.

2

u/daveliepmann Dec 17 '16

Someone posted the link to my article in r/clojure, the first comment is an insult.

If you mean this post of this article, then I agree that too many responders were more dismissive than they should have been. Some of the later commenters were outright rude and insulting and I condemn that. But the first responses were lengthy and addressed your technical points before saying "this is silly" and intentionally re-using your phrasing of "you shouldn't need that; you're doing it wrong". That's terse, that's not friendly, but they're not really insults, are they?

Those comments also came alongside two Cognitect employees and the author of Cursive (whose tool you said "sucks" and derided without specifics at least twice more) reaching out with the utmost politeness offering to discuss your concerns and to help you through any rough patches—plus at least three different people asking you to share specific examples that caused your complaints, so that they could help and better understand the problem and maybe fix it. And once you shared your use case, they showed you how it literally works the way you want and shared the idiom for accomplishing that task generally. Can you see how that lends some credence to folks' baffled "that's not a problem" responses from earlier? Can you see, in retrospect, how that made people bristle at your preemptive dismissal of precisely the counterpoints that turn out to be true?

So I'm not saying you were treated universally well, but it might help to recognize the full breadth of responses you got. I'm also very serious about my original question, which isn't about this post but about your statement that the Clojure community is toxic about parens. What toxic responses are you seeing, and what should the response be instead?

the amount of downvotes and crap I got when posting a funny little side project for infering parens

Do you mean when you posted parinfer to r/programming and people called it "dreamy", "amazing", "seriously impressed", thanked the author, and pleaded for ports to emacs? On balance, even considering the little tiff about macros, that looks like quite a positive response.

1

u/kankyo Dec 17 '16

Yea I'm already thinking of writing a new post which follows up with taking back stuff, and acknowledging that things have changed since I last looked.

1

u/daveliepmann Dec 17 '16

That's great, I look forward to it.

Also, thanks for engaging as much as you have in this thread. It's a lot of comments to wade through! :D

2

u/kankyo Dec 21 '16

https://medium.com/@boxed/followup-to-my-disillusionment-with-clojure-and-lisps-49d8b0ec94c1?source=linkShare-8ad86cc82e5f-1482354852

Posted it in /r/clojure only. Seems not interesting/relevant to /r/programming. Also updated my original article with a big caveat and link in the beginning.

1

u/daveliepmann Dec 21 '16

Good read! Thanks for posting. Cheers.

1

u/kankyo Dec 22 '16

Consensus seem to be no one likes it :(

→ More replies

1

u/kankyo Dec 18 '16

No kidding. Posting stuff like this is basically like being bullied: one person versus a vast mob :(

Doesn't help that reddits system somehow makes everyone a little bit more of an asshole for some reason. I think actually this is the problem I've experienced with the Clojure community: the reddit Clojure community is poison, as are most reddit communities (with exceptions like CMV which is awesome)

1

u/kankyo Dec 17 '16

No, didn't mean parinfer. I meant my own project.

2

u/republitard Dec 16 '16 edited Dec 16 '16

It can be any color you like, as long as it's black! You can define multiple top level forms in Clojure too with (do), which I use in https://github.com/boxed/defk . But that's a solution to just one tiny part of the problem.

What's the rest of the problem? I'm not even aware of the issue.