6 ms·
I've spent a few months learning Clojure - never gave CL a try. Here are a few thoughts on Clojure: 1. Excellent syntax and library support. It is my first Lis
by typon 8y ago
I've spent a few months learning Clojure - never gave CL a try. Here are a few thoughts on Clojure:
1. Excellent syntax and library support. It is my first Lisp, but I can't how I programmed without macros and persistent data structures.
2. I hate the stack traces. I've used both Clojure and Clojurescript (mainly cljs), and the stack traces for errors are nearly indecipherable. To be fair I am using React (not Reagent), but I don't find it too much better with other libraries.
3. I hate the build system. It is fractured and there are too many mediocre options. shadow-cljs is the best one I've used, and it works okay not great. I also hate that I can't distribute standalone binaries. I have used pkg, which distributes Node project as binaries, but the binaries are huge (something like 85MB+)
4. The core functional language is excellent, but protocols, types etc. seem much more ad-hoc and not well-designed. I'm used to object oriented (Python) and I find the lack of focus on an object-system a bit unsettling.
I have no clue if Common Lisp fixes these issues or brings new ones.
- serpix 8y agoTo date I have not come up with a situation needing protocols or objects in Clojure that could not be just done with functional programming. The real killer superpowers come from extend-type and extend-protocol. You can modify existing java/clojure libraries functionality like magic. The functional equivalent is with-binding if I remember correctly. Some Clojure libraries use protocols heavily and IMHO not just necessary.
- pjmlp 8y ago> The core functional language is excellent, but protocols, types etc. seem much more ad-hoc and not well-designed. I'm used to object oriented (Python) and I find the lack of focus on an object-system a bit unsettling. I guess CLOS was well designed. What Clojure offers is a subset of CLOS.
- cultus 8y agoClojure multimethods actually can do more than CL multiple dispatch, because they can dispatch by value rather than just type.
- guicho271828 8y agoCLOS can dispatch by value with eql specifier...
- fiddlerwoaroof 8y agoYou can implement Clojure multimethods as an extension of CLOS: https://github.com/pcostanza/filtered-functions https://github.com/pcostanza/filtered-functions
- lispm 8y ago> 2. I hate the stack traces. I've used both Clojure and Clojurescript (mainly cljs), and the stack traces for errors are nearly indecipherable. To be fair I am using React (not Reagent), but I don't find it too much better with other libraries. Stack traces are already the wrong approach. Error handling is first. Stack traces may serve some purpose, but are secondary. Common Lisp was designed for interactive error handling. An example. Let's say we have a function FAK and it returns the wrong result "0" for 0. CL-USER 21 > (defun fak (n) (if (zerop n) "0" (* n (fak (1- n))))) FAK Now we call it with the argument 10: CL-USER 22 > (fak 10) Error: In * of (1 "0") arguments should be of type NUMBER. 1 (continue) Return a value to use. 2 Supply a new second argument. 3 (abort) Return to top loop level 0. Type :b for backtrace or :c <option number> to proceed. Type :bug-form "<subject>" for a bug report template or :? for other options. The first thing you see: no stack trace. We get a clear error message and three options what to do: CONTINUE, supply a new argument, ABORT. But we also get another REPL, but this time one level down and the original REPL is still there, one level up. This means we can do some computations in the error REPL: CL-USER 23 : 1 > (fak 0) "0" CL-USER 24 : 1 > (fak 1) Error: In * of (1 "0") arguments should be of type NUMBER. 1 (continue) Return a value to use. 2 Supply a new second argument. 3 (abort) return to debug level 1. 4 Return a value to use. 5 Supply a new second argument. 6 Return to top loop level 0. Type :b for backtrace or :c <option number> to proceed. Type :bug-form "<subject>" for a bug report template or :? for other options. OOPS: we have another error. (fak 1) already does not work. Now we have more options to continue, while we are another error level deeper: 2. So we decide to go one error level up and explore the problem there further. :c 3 chooses the restart to go to debug level 1. CL-USER 25 : 2 > :c 3 Now we choose the CONTINUE restart from level 1. We just return 1 from the call, which was causing the error. The value 1 would be the correct result. Lisp now asks us for the value to use and we type 1: CL-USER 26 : 1 > :c 1 Supply a form to be evaluated and used: 1 3628800 So we explored the problem and got useful result without ever using a stack trace. Instead we used the tools: debug repls, clear error messages, restarts recovering from errors. Sure we can also get a stack trace - but the stacktrace is active in the context of the error - it's now a post-error stack trace - it's an in-error stack trace. Means we can, while we are in the error, see the stack trace and use it: change variables, restart start frames, return from stack frames, set break points to stack frames, ... Let's say we are in the error again. Let's get a quick backtrace: CL-USER 58 : 1 > :bq ERROR <- * <- FAK <- FAK <- FAK <- FAK <- FAK <- FAK <- FAK <- FAK <- FAK <- FAK <- EVAL <- CAPI::CAPI-TOP-LEVEL-FUNCTION <- CAPI::INTERACTIVE-PANE-TOP-LOOP <- MP::PROCESS-SG-FUNCTION Now we can move in the backtrace down three times: CL-USER 59 : 1 > :n Call to * CL-USER 60 : 1 > :n Interpreted call to FAK CL-USER 61 : 1 > :n Interpreted call to FAK Let's see the variables in this stack frame: CL-USER 62 : 1 > :v Interpreted call to FAK: N : 2 Okay N is 2. So FAK from 2 should be 2. Let's try to return it. We call :ret 2, which will return the value 2 from the current stack frame. CL-USER 63 : 1 > :ret 2 3628800 This gave us the correct result. We used more tools: printing a stack trace overview, moving down the stack, looking at a stack frame's bindings and returning a value from a specific stack frame. There are lots of ways to work with a stack trace while we are in the error - the display of the stack trace is only a minor feature.
- socksy 8y agoI'm not sure it's fair to bring up a fractured build system when talking about ClojureScript, and comparing it to Common Lisp, which you would not be compiling to JavaScript and interop'ing with NodeJS etc. With (JVM) Clojure, leiningen has to be 90+% of the Clojure projects in the wild. And in that world, the equivalent to a native binary is an uberjar, which is rather easy and pretty much standardized. The stack traces could be improved though.
- lispm 8y ago> Common Lisp, which you would not be compiling to JavaScript and interop'ing with NodeJS etc. https://jscl-project.github.io https://jscl-project.github.io https://common-lisp.net/project/parenscript/ https://common-lisp.net/project/parenscript/
- socksy 8y agoThat's great, are you using these? How is the interop? How does that compare with ClojureScript and shadow-cljs? How can you make a single binary? Maybe I worded wrongly the first time. I definitely didn't mean to imply that Common Lisp can't do something. That would be as foolish as saying Emacs can't do something ;) I was just pointing out that we aren't comparing like-with-like once you bring in a totally different ecosystem such as JavaScript's (which is historically neither Common Lisp's nor Clojure's main focus).
- lispm 8y ago> That's great, are you using these? Not often. In Common Lisp I don't have to use them.