Fork me on GitHub
#clojure
<
2024-07-01
>
timgilbert19:07:59

Due mostly to my own stupidity I have nuked the physical file that I just did a bunch of work in. I still have a REPL open with the old definitions currently defined in it, and I can get the function object with the code I want to recover. Is there any way to pull up some version of the original Clojure source from the REPL?

Alex Miller (Clojure team)19:07:40

Generally no. You could get bytecode and decompile it if suitably desparate

timgilbert19:07:54

Ok, cool. I'm not that desperate, but thanks for the confirmation. I'll try to see if my gray matter can work as a soft backup

oyakushev19:07:50

Unfortunately, I don't think you can even get the bytecode once it is loaded.

magnars19:07:14

Fun fact, albeit unhelpful: In Emacs Lisp, functions are their data structures, so there you could have printed them out from memory. I've used this fact to extract the parameter list from the actual function definition for use in auto-generated documentation, as one example of its applicability. 😅

👍 1
p-himik19:07:54

Just to exclude the obvious - does your REPL not have history?

timgilbert19:07:44

Not for what I need, I was working in an editor and then sending files to the repl via editor integration

timgilbert19:07:58

I had kind of assumed there was no way to get back to the source, but also last week I pulled in some code via (def f (load-file "foo.clj")) where foo.clj consisted of (fn [x ] ...), and I was surprised to see some actual source code come back when I ran (str f). So I thought maybe there might be a cached version kicking around the REPL or something.

timgilbert19:07:53

...although now I'm having trouble replicating that behavior. 🤷

valerauko03:07:54

Can you use (source function-name) to recover it?

👎 1
Joel21:07:10

How do I build a -tests.jar that includes src/test/clojure code? With pure Java and maven apparently you do this with maven-jar-plugin/test-jar. I can’t figure out how to do with with lein or clj to get clojure test code in the -tests.jar.

seancorfield21:07:14

With the CLI, you'd use build.clj and just copy the test folder as well as everything else you copy into the target folder to build the JAR.

seancorfield21:07:33

See https://clojure.org/guides/tools_build#_compiled_uberjar_application_build :

(b/copy-dir {:src-dirs ["src" "resources"]
               :target-dir class-dir})
Presumably in your project you have src/main instead of src, so you'd add src/test to that.

seancorfield21:07:02

(I can't answer the lein aspect -- haven't used it since 2015)

✔️ 1
Joel22:07:26

Thanks, really I was wanting to do this in Maven, but I’m thinking at this point to shell out from maven, as I couldn’t find info in this regard.