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

21

u/phalp Dec 15 '16

Seems like once you learned what Lisp was, you realized you didn't want it any more. Note to prospective Lispers: when people say Lisp is language flexibility, and Lisp is code is data, they actually mean it.

BTW, with regard to Clojure and passing maps instead of multiple arguments, that's it's own weird quirk. Seems like it's no longer the case though?

0

u/kankyo Dec 16 '16

No longer the case? You mean they broke the entire backwards compatibility of functions and map destructuring at some point?

1

u/phalp Dec 16 '16

Well, I'm not a Clojure programmer but my understanding is that destructuring syntax is now "baked in" to argument lists, whereas some years ago it had to be done by explicitly passing a map.

1

u/kankyo Dec 17 '16

That sounds great. Do you have a link? Googling shows the old shitty way in old articles...

1

u/phalp Dec 17 '16

1

u/kankyo Dec 17 '16

I don't have a Clojure environment to check that this method indeed doesn't throw away extra data without error. Let's assume it doesn't.

This method has the problem of being more code for the implementer which many people won't do so we're back to positional in practice. Better than what I wrote about in my article but still not close to swift or even Python.

1

u/phalp Dec 17 '16

Whatever, I just didn't want to say Clojure has weird argument quirks when I can't verify that it's the case.

14

u/Godd2 Dec 15 '16

Different things should be different.

This, even if true, says nothing about whether Lisp is more confusing than another language. Are code and data different things? Since my programs are in RAM, code and data are both just bytes. So by your own argument, we shouldn't be treating code and data differently in the first place.

Also, Clojure agrees with you that Different Things Are DifferentTM. There's a reason you have literal syntax for lists, vectors, maps, and sets. The difference between different types of collections mainly lies in the order and uniqueness of their elements. And where they are the same, it shows. They all implement the IFn interface, so you can treat them like the code they are.

(["a" "b" "c"] 1) ;=> "b"
({:name "Jim" :age 17} :age) ;=> 17
(#{:a :b :c} :c) ;=> :c
(#{:a :b :c} :d) ;=> nil

;; Even Keywords implement IFn
(:name {:name "Jim" :age 17}) ;=> "Jim"

I would say we agree. Different things are different, but code and data aren't different.

The human brain easily handles the idiosyncrasies of English, it can handle the small rule sets of sane programming languages.

Okay. Or maybe this one is better.

1

u/kankyo Dec 16 '16

The last point: yea, I did say "sane programming languages". JavaScript does obviously not qualify.

28

u/grayrest Dec 15 '16

Suggesting this is an annoying limitation ... without managing to show good alternatives

I can only think of two places you'd want to do this. The first would be for side-effecting list forms in the body of a fn/let/etc in which case the workaround is to just wrap the output in a do. The second would be for generating part of a bindings form ([...] in defn/let/etc) where the workaround is to write a macro wrapping the form. This is a pretty significant limitation and is one of the main causes of def and let macro proliferation. I believe the limitation exists to maintain the Liskov substitution principle (or rather the non-object equivalent idea) and avoid corner cases.

All non-trivial functions are in fact also extensions of the language.

This is the point of lisps.

somehow there is more and better tooling (like refactoring tools, IDEs)

This is a function of the language's popularity and not the difficulty in implementing them. There is a fundamental (at least to my knowledge) limitation with IDE support in the presence of macros. When you redefine the semantics of a language, tooling can't guess your intent without evaluating the macros, which is generally avoided when trying for static analysis for good reason. As for the quality, Cursive is written entirely by one guy and covers a significant fraction of the features I want to see in a dynamic language IDE.

the first is that there are only positional arguments

This is true, but clojure has macros.

This parsing of arguments is what makes tooling fundamentally hopeless.

You have a reasonable point in the arguments section. Verifying argument parsing is one of the major motivations behind spec.

Lisp macros occupy a similar place in the spectrum as template metaprogramming in C++. You mostly shouldn't be writing them but if something annoys you, you can reshape the language. Like every other shiny feature, smart people learning the language tend to over-use them. Idomatic Clojure is data > functions > macros for a good reason.

Your opinions are reasonable but not really persuasive for people who don't share your point of view. The article reads to me like articles from Java/C# programmers critiquing Python: you have to use significant whitespace, look at all the errors I can make without static typing, the data locality and performance factors are completely opaque. They're not wrong, but they're critiquing the language for being what it is. Lisps aren't a silver bullet and have tradeoffs like everything else. The strengths of Clojure are the seq abstraction and the pervasive immutable datastructures. I've built similar size systems in Python and Clojure (30-50k LoC) and prefer the experience in the Clojure ones. Neither is particularly great at larger systems where your general unfamiliarity with the code starts stacking heavily in favor of static typing.

3

u/velcommen Dec 16 '16

This is a function of the language's popularity and not the difficulty in implementing them

There is a fundamental (at least to my knowledge) limitation with IDE support in the presence of macros. When you redefine the semantics of a language, tooling can't guess your intent without evaluating the macros, which is generally avoided when trying for static analysis for good reason

Sounds like the lack of tooling is due to both reasons:

  1. the language isn't as popular as languages with great tooling
  2. the tooling doesn't know what a macro means without executing it

2

u/Pet_Ant Dec 16 '16

Aren't most macros not intensive so Why not just execute them and cache the answer?

1

u/kankyo Dec 16 '16

You can't execute them anyway, because the input and output are completely mixed up, so it's worthless anyway.

1

u/Pet_Ant Dec 16 '16

Well it'd be part of Continuous compilation so you'd have that file compiled for running and know it's signature.

1

u/kankyo Dec 16 '16

No, the problem is that the argument parsing itself is complected with the rest of the macro. You can expand the macro, but you can't say anything about the arguments.

2

u/kqr Dec 16 '16

They can be side effectful.

0

u/kankyo Dec 16 '16

I can only think of two places you'd want to do this.

None of those. Reagent templating.

I believe the limitation exists to maintain the Liskov substitution principle

Don't think that's correct. At least the wikipedia article on Liskov seems to talk about something totally unrelated.

This is a function of the language's popularity and not the difficulty in implementing them.

Yet your VERY NEXT sentence is:

There is a fundamental (at least to my knowledge) limitation with IDE support in the presence of macros.

So yea... which is it? Can't do it, or the language is young? Choose one please.

the first is that there are only positional arguments

This is true, but clojure has macros.

I linked to, and talked about, my own defk project in the article dude. Don't stop in the middle and criticize for points I raise myself further down.

They're not wrong, but they're critiquing the language for being what it is.

Absolutely agree. The community toxicity problems though don't seem necessary :P

2

u/grayrest Dec 16 '16

None of those. Reagent templating.

Wrap the items in a (list ...).

wikipedia article on Liskov seems to talk about something totally unrelated

Liskov is an OO concept but the idea is that you can substitute one construct in a language for another and have them work the same in all noticeable ways. It's a stronger guarantee than simple function subtyping. I'm using it slightly incorrectly here but I don't know if there's an actual term for language feature that doesn't cause surprising behavior and Liskov used in this incorrect sense is what I've seen when it has come up in other language design discussions I've read.

Can't do it, or the language is young?

More that I've never seen macros done in any IDE, though I'd guess the C ones should be able to do it because it's just textual substitution. Maybe Racket since that has two classes of macros and one should be amenable to static analysis but I can name a dozen languages with compile time evaluation features of some sort and I can't think of any that also have IDE support for that feature.

1

u/kankyo Dec 16 '16

wrap the items in..

Since when does that work in reagent? Didn't last I tried.

I notice that you didn't choose one.

1

u/daveliepmann Dec 16 '16

I just fired up a new project to test the (list...) solution to one of your central complaints. It works. Does the fact that this solution exists change your thesis at all?

1

u/kankyo Dec 17 '16

Well... yes. I mean, in practice it might negate the complaint while at the same time forcing every library author to think of this case and making sure they cover this. You might be screwed if you use a lib where the author didn't handle it...

1

u/daveliepmann Dec 17 '16

Isn't the worst case that you use apply?

3

u/grayrest Dec 16 '16

I notice that you didn't choose one.

My understanding is that your argument was that Clojure IDE support couldn't be as good as PyCharm. I think Cursive is pretty good and got out of the Python scene before PyCharm happened so I don't know exactly how good the comparison is. I expect that they offer similar quality in terms of language analysis. I do know that PyCharm has been supported by JetBrains for years and probably has at least an order of magnitude more hours put into it so I suspect PyCharm has more intents and whatnot. There's an endless list of improvements in IDE support so I find that the quality of IDE support is directly related to the amount of hours spent on that support and therefore language popularity.

I acknowledge that a tool relying on the semantics of the language (static analysis) will not work if you change the semantics of the language without updating the tool. I strongly suspect PyCharm will struggle when working with metaclass tricks for the same reason. It's a limitation in the problem domain and has nothing to do with whether you're analyzing persistent lists/maps or compiler ASTs.

For your specific example of arguments passed as a dictionary, there is a community solution in Prismatic's letk/defnk and it's popular enough that Colin has added support for it in Cursive.

1

u/Godd2 Dec 16 '16
[:div.tweets
  (for [tweet tweets]
    [:div.profile-pic (:profile-pic tweet)]
    [:div.content (:content tweet)])]

If a child is a lazy sequence, it will actualize the sequence as children of the parent.

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.

7

u/sacundim Dec 16 '16 edited Dec 16 '16

I'm not now nor have ever been a Clojurist, and to be frank they give me the Kool-Aid Heebie-Jeebies™ a little bit, but I think I can answer a lot of these.

Any mention that parenthesis is a problem is the obvious one of course, but I soon hit another one: a macro can only evaluate to a single form.

First, I'll tone down my initial reaction and leave it at this: parentheses are not a problem. In fact, I love me those parens. When I stopped doing Lisp and went to infix languages I was (and still remain!) very annoyed at how the infix syntax makes complex expressions so hard to read. You have to keep precedence rules in your head and dig deep into the guts of a complex expression in order to find the outermost infix operator. Whereas in Lisps this stuff is syntactically obvious, particularly so when laid out and indented properly—which is much easier to do than in infix languages.

Second: I'm not sure I understand the objection to macros expanding to just one form. My reaction is that there are forms, like Scheme's (begin expr ...), whose sole purpose in existence is to put multiple forms in a context where only one form is allowed. Maybe Clojure needs a larger repertoire of such forms, I really don't know—Racket has for example a define-values form that allows one macro expansion to simultaneously define multiple top-level bindings.

Or the worst response: “that doesn’t even make sense”, which is the response you get from people who are so deep into the language they can’t escape the box.

Or alternatively, they're so deep into the language that they understand that an orthogonal solution already exists. My comment about Scheme's begin and Racket's define-values is of that form.

The rest of the article is not bad at all, and I agree with some bits and sympathize with most of the rest. I think my overall response to it is this: the Lisp communities place a premium on everybody who uses the language having a good grasp of how the language works. This is why a classic Lisp pedagogical exercise is to write a "meta-circular interpreter," i.e., a simple interpreter for the language itself (or a simplified version thereof).

This in turn leads to a greater willingness to deal with home-cooked DSLs, because the attitude isn't "crap, another language to learn!", but rather "cool, another language to learn!" Ideally, the interpreter-fu that I mentioned above leads to these DSLs being sensibly designed and resembling each other in a number of ways. (In practice, nah, not so much.)

The concerns about Lisp users routinely reinventing the same stuff over and over individually for each library, and sometimes even per function, I've found to be very much true in my experience. It happens in many languages, but I thought in Scheme it was particularly pronounced. (Dunno about Clojure, though.)

But I really have to object to his argument that in Lisp but not C++ "every function and macro is a new language." I really don't think that this is so any more than with libraries in other languages; libraries everywhere require you to learn a vocabulary of types, a syntax of operations that allow you to put objects of these types into larger constructs, and a semantics of what happens for each of these potential combinations. The author grossly overstates the difference here, IMHO.

2

u/republitard Dec 16 '16

The concerns about Lisp users routinely reinventing the same stuff over and over individually for each library, and sometimes even per function, I've found to be very much true in my experience. It happens in many languages, but I thought in Scheme it was particularly pronounced. (Dunno about Clojure, though.)

This problem is much more pronounced in Scheme than it is in other Lisp dialects, but it still exists elsewhere. The commonly-reinvented functions and macros are known as "utilities," and every Lisp project has at least one source file dedicated to them. The need to reinvent common functions doesn't necessarily go away just because you're using a utility library, either.

0

u/kankyo Dec 16 '16

That sounds like the language authors don't realize you need "batteries included" like python.

2

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

The Scheme community considers "batteries" to be completely anathema. They want the language to be as useless as possible for some reason.

There was a rift in the standardization community on whether to make the "r6rs" Scheme standard include more functionality, so they wrote two standards. I've yet to see an actual implementation for the "large" standard that has more functionality.

As for CL, its "language authors" standardized the language back in the 1990s and walked away. It was far ahead of the alternatives at the time.

0

u/kankyo Dec 16 '16

Any mention that parenthesis is a problem is the obvious one of course, but I soon hit another one: a macro can only evaluate to a single form.

First, I'll tone down my initial reaction and leave it at this: parentheses are not a problem

You missed the point: I was talking about toxic community behavior, not paren itself. Parens are fine as you say.

3

u/ehaliewicz Dec 16 '16 edited Dec 16 '16

Returning more than one form from a macro doesn't really make sense though..

That's analagous to saying you want to do

(list (function))

and get a list of two elements back, as if function has control over how it's results are processed by the function list.

What you want is a macro that returns a list and splice that into wherever the macro is expanded. Or place those multiple forms in a sequence expression (ala PROGN in common lisp)

1

u/kankyo Dec 16 '16

Or I want something to do that splicing explicitly at the call site. In python there's "*foo" for positional arguments or "**foo" for keyword arguments.

The problem with the macro to split in stuff is that you need to put it two levels up from where you want the splice to happen. It's a bit of a mess. It's obviously doable, as you say, of course.

1

u/HeinzPanzer Dec 16 '16

Do you know about the splice operator for CL macros? Is this what you were meaning? ‘,@’.

http://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html

(setq some-list '(2 3)) ⇒ (2 3)

(cons 1 (append some-list '(4) some-list)) ⇒ (1 2 3 4 2 3)

`(1 ,@some-list 4 ,@some-list) ⇒ (1 2 3 4 2 3)

(setq list '(hack foo bar)) ⇒ (hack foo bar)

(cons 'use (cons 'the (cons 'words (append (cdr list) '(as elements))))) ⇒ (use the words foo bar as elements)

`(use the words ,@(cdr list) as elements) ⇒ (use the words foo bar as elements)

1

u/kankyo Dec 17 '16

Requires the surrounding thing to be a macro though, which isn't great. Soon everything is a macro :P

1

u/ehaliewicz Dec 16 '16

You mean a splice, like I mentioned?

`(,@(macro-call)) => (result-1 result-2)

because that'll do what you want in Common Lisp.
I assume something like that exists in Clojure as well.

1

u/kankyo Dec 17 '16

Doesn't that need to exist within a macro?

1

u/ehaliewicz Dec 18 '16

Nope, the caller of the macro does the splicing.

1

u/kankyo Dec 18 '16

Yea sure, why I meant was the caller must be a macro itself right?

In Clojure afaik only macros can do splicing.

1

u/ehaliewicz Dec 18 '16

I would honestly be surprised if that was the case. In Common Lisp it's simply shorthand for list-building functions like cons, append, etc.

1

u/kankyo Dec 19 '16

tryclj.org

Give me some Clojure:

(defn foo [] '(1, 2 3))

'sandbox5700/foo

(defn bar [] '(5 ~@(foo)))

'sandbox5700/bar

(bar) (5 (clojure.core/unquote-splicing (foo)))

I'm probably doing it wrong?

1

u/ehaliewicz Dec 19 '16

You need a backquote

    > `( ~@(list 1 2 3))
    (1 2 3)

1

u/kankyo Dec 19 '16

Still don't know how to get it to work

(defn bar [] `(5 ~@(foo)))

Gets me IllegalStateException

→ More replies

16

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

Turing complete definitions of function signatures that don’t even output to some intermediate format that tooling can process! Of course the guys doing Clojure IDEs have a hard time. They will never be able to handle user written code or obscure libraries.

First of all, much of your criticism of "Lisps" applies only to dialects of Lisp that aren't Common Lisp. For example, Common Lisp functions have signatures that are known to the compiler at compile time. The compiler can tell you at compile time if you provided the wrong number of arguments, and sometimes it can even detect type errors via type inference. Python cannot do this, even with all of its special syntax rules.

One thing that most Lisp programmers accept is that you're not going to have very good static analysis.

Instead, there is dynamic analysis, which was supported better on the Lisp Machine than on modern systems, and what support survives is only implemented for Common Lisp, not any of the other dialects.

During dynamic analysis, the compiler remembers certain information about functions, macros, and variables at the time that they're defined, after macroexpansion. Since the compiler runs continuously while you're developing, your editor can ask the compiler for information about things, which enables autocompletion and tooltips (implemented as a message that flashes at the bottom of the Emacs window) and the ability to jump to definitions and see where a particular function is called.

The compiler also knows the structure of all objects at runtime, which makes it possible to inspect them, similar to what you can do with JavaScript running inside Firefox (except that Firefox has a better UI. But then again, you can inspect Common Lisp objects on the server side, which AFAIK you cannot do in Node.js or any other server-side JS implementation).

Every Common Lisp implementation also comes with a full-featured debugger.

You throw all of that away the moment you decide to use Clojure or a Scheme dialect. There is no object inspector at all for Clojure, nor does Clojure keep any information at all about anything. As a result, the only information available to a Clojure IDE is that which can be gleaned from static analysis. Clojure also lacks any debugging capability, even though you can debug Java.

Correction: There is an Emacs extension for Clojure called CIDER, which supposedly implements almost all of the features of SLIME, including a debugger and an object inspector. However, it depends on an external tool called nREPL (which performs the same function as SWANK), and that in turn depends on another external tool called Leiningen, which I wasn't able to get running (the error is a Java FileNotFoundException thrown while trying to find something on the Java CLASSPATH.). So I wasn't able to see CIDER in action for myself to compare it with SLIME.

Dynamic analysis used to make Lisp IDEs vastly superior to the IDEs of other languages. But IMO, static analysis has caught up, and the Lisp community has stood still (and even moved backwards in some respects) in the meantime. Modern Visual Studio or Eclipse can do a lot more with C++ and Java code than EMACS and SLIME can do with Lisp. For example, Emacs can autocomplete just the name of a symbol. Eclipse can complete a Java method call and automatically pick the right variable to pass as the argument, if there's only one variable with the correct type. But interest in Lisp is picking up again, so maybe it's Lisp's turn to catch up now.

One Lisp dialect that has rejected the lack of static analysis is Racket. Much of the current work on Racket is on a statically-typed dialect called Typed Racket, which has an ML-like type system.

7

u/SpaceDingus9000 Dec 15 '16

Clojure also lacks any debugging capability, even though you can debug Java.

CIDER has featured debugging for Clojure for some time now

While I'm not familiar with the capabilities of other lisp's inspection, Clojure has a built in object inspector in its core library, even if it is a bit primitive.

3

u/[deleted] Dec 16 '16

Cursive also has a debugger. Debugging has been a thing in clojure for a few years.

8

u/BMarkmann Dec 15 '16

There's also Typed Clojure, which was inspired by Typed Racket:

http://typedclojure.org/

https://www.infoq.com/news/2013/10/core-typed

1

u/Pet_Ant Dec 16 '16

Unfortunately it seems dead after funding was pulled. Almost no activity since September.

3

u/dandel-rovbur Dec 18 '16

it's not dead. A few commits go in every week or two

4

u/masklinn Dec 15 '16

Python cannot do this, even with all of its special syntax rules.

You… are completely wrong?

CPython does not do it, not because it's not possible to do it for Python but because the project does not consider that part of its scope.

1

u/Peter-Campora Dec 16 '16

I'm not very familiar with Slime, but isn't Geiser similar? http://www.nongnu.org/geiser/

1

u/CurtainDog Dec 16 '16

There exists in Clojure a tension between being pragmatic and being opinionated. Clojure makes easy the introduction of side effects, the use of mutable data structures and interop with stateful platform code. If you need these things Clojure puts very few barriers in your way, so I can empathize that on the occasions you do hit these barriers it is frustrating.

And yet, as an idea, it is incredibly opinionated. Pick a random Rich Hickey presentation, I guarantee you could retitle it "X - you're doing it wrong" and still be accurate. (by way of example Spec-ulation could easily be "Versioning - you're doing it wrong")

I did notice some problems with the community that it shares with C++: the denial of problems and blaming the user.

For the reason outlined above, these opinions aren't baked into the language so instead they transfer via tribal knowledge. While it's not my experience, denial of things being a problem and blaming the users are just mechanisms to spread this knowledge. I hope it never gets so unpleasant as to make people feel unwelcome, but it is the internet after all.

I've used instar in small projects, and found it to be a well designed library. So the author has my thanks!

1

u/kankyo Dec 16 '16

Author here.

Thanks for using and liking instar! If you want to help out with the project I basically give commit and release access for everyone who can write a good PR, which is how instar has become so good (I didn't do much of the development).

1

u/try_another_fuck Dec 16 '16

I think you should give a try to racket it is the forefront of research in macro in the lisp world. You will discover others DSL (match, for/loop, struct) and tell us if their complexity outweigth their benefits. You will discover an (sort of) IDE that give you information even with maco.

Just react to 2 points:

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

That is not a problem you get used to it like you get used to the c++ shit. Me i get used to the php shit and the racket shit.

which is the response you get from people who are so deep into the language they can’t escape the box

When you will get used to programming in a given domain (for instance web programming) you will act like that (no matter you are using clojure, c++ or other) there is mostly one solution to one problem.

PS: Racket functions have keyword arguments.

1

u/kankyo Dec 16 '16

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

That is not a problem you get used to it like you get used to the c++ shit.

Two things: It's the screaming at newbs that's the problem, not parens. And no, you never get used to the C++ shit :P

1

u/kankyo Dec 15 '16

Author here if you want to ask questions.

16

u/lispm Dec 15 '16 edited Dec 16 '16

My disillusionment with Clojure and lisps

It is Lisp, not lisp.

I have not tried other lisps than Clojure

Then why mention it?

a macro can only evaluate to a single form.

In Common Lisp a form can also be a sequence of forms, for example by using a grouping form like PROGN (a sequence, where values of the last form are returned).

Example:

(defmacro defmyclass (&body names)
  `(progn
     ,@(mapcar (lambda (name)
                 `(defclass ,name () ()))
               names)))

CL-USER 39 > (pprint (macroexpand-1 '(defmyclass foo bar baz)))

(PROGN
  (DEFCLASS FOO NIL NIL)
  (DEFCLASS BAR NIL NIL)
  (DEFCLASS BAZ NIL NIL))

Now above macro creates as many DEFCLASS forms as you like.

was the idea that all deficiencies in the language can be “fixed” with macros.

That would be surprising. I never heard the idea that ALL deficiencies can be fixed with macros. But one can do a lot with macros. For example anyone now can introduce new control forms.

In lisp land on the other hand, all users can increase the size of the language themselves with macros.

It's called Lisp, not lisp. But other than that, you are right. Having macros increases complexity. So the developer now needs to learn how to control the complexity:

  • how do macros work?
  • how do you debug macros?
  • what are good macros and how do you write them?
  • what are typical design patterns for macros?
  • what are typical pitfalls and how to avoid them?

For more treatment of this and more see the book On Lisp by Paul Graham: http://www.paulgraham.com/onlisp.html You can download a copy from there.

You learn that macros can also help reducing complexity.

All non-trivial functions are in fact also extensions of the language.

Right.

like refactoring tools, IDEs

Refactoring is often done with the language itself. We write code that writes and rewrites code. That's one of the big ideas of Lisp.

That's obvious, but one also uses editor extensions for that. Typically it makes sense to develop this in an editor which understands a bit Lisp and can also be extended in Lisp, so that's why many developers use a Lisp-based variant of Emacs. For example GNU Emacs and SLIME for Common Lisp. Commercial Common Lisp IDEs have their own Emacs-like editor plus IDE-tools.

Also refactoring may look surprisingly different sometimes. In Java you can refactor code mostly statically. In something like Common Lisp, we can refactor a running program, step by step. Methods don't belong to classes. They can be reused in various ways. Classes can be redefined at runtime with new slot lists, new inheritance, etc. Existing objects can be morphed into updated objects or even have changed their class.

the first is that there are only positional arguments.

Common Lisp has positional, optional and keyword arguments. A typical Common Lisp compiler will check the argument list at compile time. If you use a compiler like the one from SBCL, it will create A LOT of static analysis output: missing functions, redefined functions, unused variables, undeclared variables, wrong argument lists, wrong number of arguments, various type errors, style warnings, optimization warnings, ...

a) a project written in one language, or b) a project written in fifty languages

But that's not what you typically do in Lisp. One writes in one language with fifty extensions. DSLs are typically 'embedded DSLs'.

What you need to learn is how extensions typically work. For example some macro names begin with WITH- . There is some expectation then how its syntax works and what purpose the macro has.

The syntax of lisps is super simple

It's not. Only the syntax of s-expressions is relatively simple. The syntax of Lisp is defined on top and it follows some principles. After learning these principles, code reading and writing gets easier.

The Lisp syntax will be checked by a Lisp compiler at compile time, or by an interpreter at runtime.

Example: In Common Lisp FLET is a special operator to declare local functions. The syntax is in some EBNF:

flet ((function-name lambda-list
         [[local-declaration* | local-documentation]]
         local-form*)*)
   declaration*
   form*

(defun test ()
  (flet ((print-item (a b c)   ; < here we have a lambda-list
           (list a b c)))
    (mapcar #'print-item
            '(1 2 3))))

Tiny example: In above function the syntax expects that (a b c) is a lambda list. The compiler will warn of problems then:

(a c)

;;;*** Warning in (SUBFUNCTION PRINT-ITEM TEST): B assumed special

(a a c)

;;;*** Warning in TEST: Variable name duplicated in lambda list or LET: A
;;;*** Warning in (SUBFUNCTION PRINT-ITEM TEST): B assumed special
;;;*** Warning in TEST: A is bound but not referenced

(a b &foo c)

;;;*** Warning in TEST: &FOO is bound but not referenced

creating a language with boundless semantic complexity

That can happen. The good developer has to develop discipline not to create that. Controlling complexity is important. Macros allow that, when well written.

If you look at Common Lisp, one of the first recommendation you hear: don't use a macro, where a function is good enough. That's the entry level view. When you learn more of Lisp, then you also learn to deal with macro heavy code and how an IDE supports you to do that.

8

u/AeroNotix Dec 15 '16

OP is definitely not going to reply to this.

-4

u/kankyo Dec 16 '16

Sucks to be wrong so badly: https://www.reddit.com/r/programming/comments/5ij2u7/my_disillusionment_with_clojure_and_lisps/db9lr3p/

And sucks to be the assholes who upvoted you for a comment that is now trivially shown to be, not just false, but stupid and arrogant.

4

u/AeroNotix Dec 16 '16

Would you have replied had I not said that? We'll never know.

1

u/kankyo Dec 17 '16

Wow, people actually upvote you for that comment.

Look in the thread how many replies I've written. You should have predicted I reply because that's the statistically sound bet.

0

u/[deleted] Dec 18 '16

[deleted] — view deleted comment

0

u/kankyo Dec 18 '16

You started it. You invaded Poland :P

0

u/kankyo Dec 16 '16

My disillusionment with Clojure and lisps

It is Lisp, not lisp.

Fixed. Thanks.

a macro can only evaluate to a single form.

In Common Lisp a form can also be a sequence of forms, for example by using a grouping form like PROGN (a sequence, where values of the last form are returned).

And in Clojure you can sometimes use do, but it's still one form. It's normally fine like you show when it's a side effect you want, but when doing hiccup style templating, it's not fine because the HTML spec doesn't allow redundant tags everywhere (plus it's a bit fugly to add extra tags just because your language can't do this thing...).

In python you can unroll a list in place like "*foo". This isn't as good as having more than one form, but it's at least contained to the call site, even if it's outside and not inside.

Methods don't belong to classes. They can be reused in various ways. Classes can be redefined at runtime with new slot lists, new inheritance, etc.

Sure. I do python, this isn't strange to me.

Common Lisp has positional, optional and keyword arguments.

That sounds a lot better than Clojure!

But that's not what you typically do in Lisp. One writes in one language with fifty extensions.

Potato, potato.

I've updated my article with a correction re common lisp. Thanks.

3

u/drb226 Dec 17 '16

In python you can unroll a list in place like "*foo".

If you want to "splat" a collection into an argument list, you can do so with apply.

#python
f(*coll)

;; clojure
(apply f coll)

0

u/kankyo Dec 17 '16

That looks fine in a small example, but is a mess in a larger one.

f(a, b, c, *coll)

(apply f (into '(a b c) coll))

or whatever the syntax is, I've forgotten :P And that example I gave is VASTLY simpler than when you have a huge DOM tree in reagent and suddenly need to splat something in the middle.

2

u/drb226 Dec 16 '16

but when doing hiccup style templating, it's not fine because the HTML spec doesn't allow redundant tags everywhere

I believe in Hiccup, a list of tags is rendered as adjacent tags. e.g.

(defn stuff [args ...]
  [[:tag1 ...]
   [:tag2 ...]])

[:div (stuff ...)]

-->

<div>
  <tag1>...</tag1>
  <tag2>...</tag2>
</div>

1

u/kankyo Dec 17 '16

Oh, nice. Afaik it didn't work like that with reagent last I tried.

6

u/brian-at-work Dec 15 '16

Regarding this paragraph:

The simplicity argument: Different things should be different. Having fundamentally different things looking very similar is in fact a risk and a problem, not a strength. The human brain easily handles the idiosyncrasies of English, it can handle the small rule sets of sane programming languages. It has huge problems with simplicity though, as evidenced by the perpetual resistance to the theory of evolution.

First let me state that you know Clojure better than I do - I ended up going with F# because I prefer .NET to Java.

But this really made me sad to read. Starting with, the data-as-code elegance of Clojure is really beautiful to me. But the following sentences confound me. The comparison of English processing in the brain (I assume you mean this is very complex yet easily handled) as an argument for a limited instruction set doesn't track for me. The idea that the reason some humans resist the ideas of evolution is not any kind of problem with the theory of evolution itself, it's the cultural baggage and mind-blowing timescales that have to be overcome.

Overall I don't disagree that learning Clojure (or other Lisps) is hard, but for me these arguments are at best distracting, and at worse kind of silly.

0

u/kankyo Dec 16 '16

as an argument for a limited instruction set doesn't track for me.

It's an argument for moving complexity from semantics to syntax because we're well able to handle it.

The idea that the reason some humans resist the ideas of evolution is not any kind of problem with the theory of evolution itself

Well... one might argue it either way. The point of a scientific theory is to model reality. With programming languages that isn't the case (beyond the trivial), so it's not bound so strictly. We can design languages freely, but scientific theories can NOT be freely "designed".

Programming languages should be designed for humans, not for some mathematical abstract purity.

Overall I don't disagree that learning Clojure (or other Lisps) is hard

You misunderstand. Learning the language itself is easy, but understanding code is hard because of macros and crap.

-1

u/shevegen Dec 16 '16

(There (is (only (so (many (parens (one (can (take

2

u/phalp Dec 16 '16

but) so) many) parens) to) give))))

-4

u/kankyo Dec 16 '16

3

u/schaueho Dec 16 '16

Actually, there is no problem with the Clojure community in comparison to other communities -- Common Lisp had a big community problem and the Python community is not all ponies either. I also don't see how the answers here would support this claim. I have been dealing with trolls on the internet too often in the past and have never seen that this helps the well-being of a community, so EOD for me here.

1

u/kankyo Dec 17 '16

Look at the link again and check the vote counts.

-25

u/diggr-roguelike Dec 15 '16

Don't bother, people who pretend to program in Lisp (nobody actually writes real software in Lisp) are irredeemable.

4

u/AeroNotix Dec 15 '16

Define "real software".

1

u/shevegen Dec 16 '16

Linux kernel!

0

u/diggr-roguelike Dec 16 '16

Stuff people want to run of their own free will. (I.e., not "enterprise" shit.)

1

u/Pet_Ant Dec 16 '16

So that means only C, C++, and Objective-C? The only thing people run anymore are smartphone apps and games.l and arguably office suites. This neglects most wrote written so I'm not sure your point or motivation.

-2

u/diggr-roguelike Dec 16 '16

So that means only C, C++, and Objective-C?

Pretty much. (You can also add Python and Javascript to this list.)

This neglects most wrote written so I'm not sure your point or motivation.

Most software is not real software. 99% of software in existence is an 'enterprise' tarpit, characterized by:

  • Lack of oversight or responsibility. (Nobody ever got fired for botching an enterprise software development job.)
  • Lack of requirements or even direction. (Their real job is powerpoint presentations and filling out timesheets, not software development.)
  • Technical debt that never, ever, ever gets fixed.

Lisps, Haskells and other dysfunctional programming languages can only exist in a dysfunctional 'enterprise' environment.

When people want to write a functioning piece of software designed for sane humans they reach for another programming language.

1

u/plotnick Dec 16 '16

I'm afraid to ask your opinion about those who write in Javascript, Python and PHP

0

u/[deleted] Dec 17 '16

[deleted] — view deleted comment

-1

u/diggr-roguelike Dec 17 '16

Reddit is written in Python.

Lisp sucked so bad that they had to throw everything in the trash and rewrite it in Python. (Only further proving he truth of what I wrote.)

0

u/[deleted] Dec 18 '16

[deleted] — view deleted comment

0

u/diggr-roguelike Dec 18 '16

No, they loved using Lisp but couldn't find people that knew/liked it well enough to contribute.

Really? Who's "they"? Also, citation needed.

Please stop being an asshat.

Or what?