2
votes

Question

Is it possible to split load-file into two steps:

(1) compile and
(2) load ?

Context

I'm doing hot code reloading to a remote machine. I don't want to ship the source over to the machine, then thane the machine load-file it. Instead, I want to ship a *.class file over to the machine, and have the machine just reload the namespace with the *.class

Thus, I want a way to:

(1) transform *.clj files to *.class files that can be hot-reloaded

and

(2) I need to be able to call remove-ns on them later (when they have to be replaced)

EDIT

I'm also perfectly happy using (require :reload ... ) -- again, as long as I can just provide it a *.class file instead of my *.clj files.

Thanks!

1

1 Answers

0
votes

Short answer:

  1. On your local machine, use compile to compile your clojure source into .class files.
  2. Upload those to your remote server.
  3. Use require to (re)load the namespaces.

In your source code, you should rely on require instead or load-file, specifically for this reason. At runtime, you can't be sure whether the namespaces will come from a source file, a compiled binary.