by iLemming · 6y ago · 0 comments
Today it is possible to run Clojure on:
JVM, JS, BEAM, .NET CLR, Common Lisp runtimes;
Have interop with Python and R. There are Clojure-like Lisp dialects that can compile to Lua and C.
> you don't need the Clojure repl
If you never have experienced the joy of using "true" REPL, you will never understand the immense value of it. Non-lispy languages, sadly have no "true" REPLs.
No, it is still would be very crippled imitation of REPL, merely interactive environment. For a language to have a fully-functional REPL, it is required to have at least some homoiconicity, which JS is not.
Let me demonstrate:
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
Can you evaluate that in JS REPL? Can you evaluate any part of it?Now, let's naively "convert" that into Clojurescript:
(ReactDOM.render
[:h1 "Hello, world!"]
(document.getElementById "root"))
You can evaluate every single part of it. You can evaluate "Hello, world!" string; [:h1 ...] vector; document.getElementById function, all these are valid Clojure expressions.
In addition to that - Clojure example is so much easier to modify and change. With just a few keystrokes, you can do a lot.That's basically the workflow - in Clojure, you bootstrap an app with some small, core dependencies, then start a REPL, connect to it and keep modifying your app while running it. That is what gives so much praised productivity boost. It doesn't matter how fast your compiler is (in other languages) - "save & recompile" workflow never going to be as good as working with a "true" REPL.
In another comment you gave an example like: (foo [a b] ((c a) b)) stating that you can eval any part of it, but if you try to eval ((c a) b), won't the repl raise an error stating a and b are not defined?
You see, in Lisp you think and operate in units of s-expressions, any s-expression can be send to the REPL as-is, "code is data" <=> "data is code". In Javascript it also adds some hurdles of things being out of scope. In Clojure, due to default immutability - the problem space is usually small, it encourages you to write smaller functions and it is much simpler model - most of the time you can evaluate anything without any preceding ceremony. In some cases you do need to set the context as you pointed with `((ca) b)` example, but it's so trivial to do so with s-expressions and it's so tedious when working with Javascript (trust me, the comparison not in favor of the latter, I've built JS apps for over a decade).
I don't quite understand this, could you explain it a little more in depth?
But I think one has to experience it, to understand what makes languages like Lisp and Smalltalk so special, what is so unique about REPL driven workflow that even Python's so much praised Jupyter can't give you that satisfactory feeling.
It's really nice to be able to run anything - from the smallest unit in your program, as well as the whole program and see the immediate feedback. For example: You can evaluate SQL DSL constructs and see what SQL query they compose into, and you can run that query and see the results (all without ever having to write a single line of actual SQL); or you can connect to the browser and change elements of the DOM (without writing a single line of html, css or js).
You can take a complex piece of code that generates a .csv, and then analyze that csv on the fly, changing columns and rows on the go, without even saving and having to wait for the compiler to pass the checks.
You can compose music and data visualizations, and etc.