4 ms·
> For example, you define a function in the repl, or assign a value to a variable. You’re just supposed to keep the existence of those declarations in your head
by TacticalCoder 4y ago
> For example, you define a function in the repl, or assign a value to a variable. You’re just supposed to keep the existence of those declarations in your head?
If you're using a LSP server, which btw uses the "clj-kondo" which borkdude mentioned, it's totally independent from the REPL and will tell you immediately if your source file is missing a function definition or a variable.
Now it could be argued that you could have a wrong version of a function declared in the source file (and hence LSP / clj-kondo would still be happy) while the correct version got only defined at the REPL but...
That's not how I develop: typically I test stuff at the REPL but only define my functions in the source file. And from the source file, I "eval" the function and its hence available directly in the REPL.
Now I don't know about others but in my case I regularly write anonymous functions at the REPL, which I test directly on some data at the REPL, and then I copy/paste the anonymous function to the source file and give it a name there.
REPL> ((fn [x] (* x 2) 21)
42
OK, good, it works now, I cut/past (fn[x] (* x 2)) to the source file and change the anonymous fn to a defn.
But I'll also sometimes just directly write the function in the source code file.
In addition to that, unit tests can help too.
So it's REPL + unit tests + LSP (which uses clj-kondo) and all three are totally independent.
And yet although they're independent, when LSP tells me something like: "Function x is called with only argument but expects two", I can fix it, eval the correct function, and the REPL is immediately aware of the correct version.
I've always got both the REPL and the Clojure LSP server running, independently, simultaneously.
> or assign a value to a variable.
Clojure really tries to put the emphasis on functional programming so you don't typically have lots of mutable variables to juggle with. I'd say I have more of a "global application state" at the REPL than different variables.
> I must be missing something.
Maybe you're simply not aware that you can code in the source file, eval there, and the eval'ed functions are directly available from the REPL?
I'm not sure my explanation are very clear but I hope it helps.