5 ms·
So, why not clojure? (Warning: subjective, and a bit toungue in cheek): - Clojure is a Lisp. Lisps are very elegant in their simple tree syntax, so compilers l
by alkonaut 10y ago
So, why not clojure? (Warning: subjective, and a bit toungue in cheek):
- Clojure is a Lisp. Lisps are very elegant in their simple tree syntax, so compilers like them, and reasoning about Lisp code is a joy. However no one has yet figured out how to represent Lisp code in good a way that doesn't require a large number of parentheses, often stacked together in groups of three or four. If you have a slight astigmatism this (((()) will not help.
- It's a jvm language. That has gives all the benefits you want in a functional language such as type erasure meaning you can't make a data structure of primitive types without either pretending they are objects (boxing) or writing a custom type. Also, you have access to the vast amount of jvm libraries, almost all of which use mutable data structures and nulls everywhere. Jvm lacking proper tail calls will also give you the joy of having to manually specify when you want tail recursion rather than just recursion...from the tail.
- junke 10y ago> compilers like them Editors too.
- sandbags 10y agoAlthough macros can make life difficult for clever editors that want to introspect code.
- yogthos 10y agoThis is mitigated by the fact that Clojure doesn't expose reader macros to the user.
- adrianm 10y agoDon't macros actually help both compiler writers and end users here? Macros are expanded at macro-expansion time, which is a stage before code gets evaluated. Macro-expansion is akin to source code pre-processing in other languages. Therefore all necessary context for fully expanding a macro in Lisp is maximally a source file and minimally a single macro form within some shared compilation environment. Clever editors (like Emacs extensions commonly used by Scheme, Common Lisp, and Clojure programmers) make ample use of this functionality to provide all sorts of code introspection and other smart editing functionality.
- alkonaut 10y agoSyntax level macros (like C) are unhygienic and basically dangerous, while proper (ast-transforming rather than syntax transforming) hygienic macros are ok for both tools and humans. Macros got a bad reputation just because there were poorly implemented for C.
- nemoniac 10y agoSLIME is your friend. Stepwise forward and backward macro expansion and contraction. It's a thing of beauty.
- yogthos 10y agoIn practice you end up with less parens than in most languages to express the same thing though. Also, the parens are largely what allows for structural editing: https://cursive-ide.com/userguide/paredit.html https://cursive-ide.com/userguide/paredit.html When I work with Clojure, I'm able to think in terms of blocks of logic as opposed to lines of code. This is extremely powerful. The JVM is certainly not a limitation for many applications out there. Conversely, since Clojure has recur, the only time lack of TCO comes into play is when you're trying to do mutual recursion. I haven't run into a single case where I needed that in 6 years working with the language professionally. However, Clojure is not really tied to the JVM. It runs on both Node.js and CLR. I'm actually currently working on a Node based micro-framework for Clojure: https://github.com/macchiato-framework/macchiato-core https://github.com/macchiato-framework/macchiato-core
- greggyb 10y agoFunCall1( FunCall2( FunCall3(arg1, arg2, arg3))) vs (FunCall1 (FunCall2 (FunCall3 arg1 arg2 arg3))) Yes those useless parentheses certainly clutter up the code. Look at how much longer the lispy line is compared to the less lispy line. Why it's got a whole -3 more characters! And the end of the line with all the parentheses. So much uglier to see three parens at the end of the lisp line than the non-lispy line. Truly a monstrous imposition, that lisp syntax. And when you look at any lisp code base, look at how they don't indent their code at all. So unlike other languages. Here's literally the first project I could find looking for "lisp source code": https://github.com/adamtornhill/LispForTheWeb/blob/master/web_with_persistent_backend.lisp https://github.com/adamtornhill/LispForTheWeb/blob/master/we...
- Rovanion 10y agoWhich can be rewritten as: (-> (FunCall3 arg1 arg2 arg3) Funcall2 Funcall1) in Clojure. https://clojuredocs.org/clojure.core/-%3E https://clojuredocs.org/clojure.core/-%3E
- greggyb 10y agoSo, you're telling me that users of a language known for syntactic abstraction came up with a way to more conveniently express a common pattern of code? Well color me flabbergasted.
- alkonaut 10y agoTo be fair, both the imperative and the lisp version of that are probably not optimal. In most imperative (OO) languages the first one could hopefully be Fun3().Fun2().Fun1() or even thing3.thing2.thing1 If some thing is a property of the other Concrete example from your linke: a projection and sort (I believe it is). I think that the tail of this expression with 5 parentheses makes this very hard to read (Admittedly it's a matter of experience of course): (docs (iter (db.sort *game-collection* :all :field "votes" :asc nil))))) Questions I find hard to answer for the above line is: how many args does "iter" have? Is 5 trailing parentheses the right number? Here is some half-functional half-imperative strawman syntax: for comparison: x = some_collection .select(c -> c.documents) .sort(d -> d["votes"], direction: ascending); I find that a lot easier to balance, and know how many arguments the projection has compared to the sort.
- Rovanion 10y agoI find -> and its brethren helps quite a lot.
- kazinator 10y ago> However no one has yet figured out how to represent Lisp code in good a way that doesn't require a large number of parentheses, often stacked together in groups of three or four. Ah, not so! In some ancient Lisp dialects decades ago, there existed an invention known as the "super bracket". Namely the closing square bracket ] would simultaneously close any number of outstanding open parentheses up to the nearest opening [. For instance [foo (bar (1 2 3] could be written instead of (foo (bar (1 2 3))). It's not really such a great idea so it didn't catch on.
- kazinator 10y agoLooks like it was none other than InterLisp which had this, mentioned in P. Gabriel's and G. Steele's Evolution of Lisp paper: https://www.dreamsongs.com/Files/HOPL2-Uncut.pdf https://www.dreamsongs.com/Files/HOPL2-Uncut.pdf P. 18.
- alkonaut 10y agoThanks, at least it seems to indicate that someone other than me had an issue with telling N parens from N-1 parens in a row. I think this is a pretty common syntax problem, it's for example why I prefer xml to json for human editable data despite the extra verbosity - each ending is explicitly labeled. The Foo(Bar(Baz))) calling style is of course equally broken.
- deleted 10y ago[deleted]
- LyndsySimon 10y ago> However no one has yet figured out how to represent Lisp code in good a way that doesn't require a large number of parentheses, often stacked together in groups of three or four. Parinfer solved this problem for me: https://shaunlebron.github.io/parinfer/ https://shaunlebron.github.io/parinfer/