Fork me on GitHub

When visiting a Clojure file in a base, I invoke cider-jack-in, this starts a REPL which reads the dep.edn file of the base, what I intended was to read the deps.edn file in the root of the workspace, has anyone had this problem and found a way around this? (I am aware that this is the correct behaviour, just wondering if anymore has a work around to always read the workspace deps.edn config)


I always do the initial connect to the REPL via the user or dev ns in the development project.


Yea I've been doing the same

Karol Wójcik15:08:39

@U05476190 how do you setup the nrepl?


I just run clojure -M:with:lots:of:dev:aliases and then cider-connect-clj. I never figured out how to use cider-jack-in and find it easier to configure the REPL classpath via CLI tools :)


At work we always start the REPL from the terminal because our REPL outlives our editor sessions (we run REPLs for days or weeks -- or sometimes months) but our editors tend to get restarted a lot more often.


My work REPL has been running since August 11th at this point (not very long) but my HoneySQL project REPL has been running since July 18th.


(and my depstar project REPL has been running since July 9th)


My work REPL is started like this:

(! 509)-> SOCKET_REPL_PORT=5000 clojure -Sforce -M:rebel:reflect:jedi-time:reveal:j14:classes:everything:dev:test:build:runner:dev/repl
That :dev/repl alias comes from my dot-clojure repo setup on GitHub and starts Rebel Readline, Reveal, and a Socket REPL, plus it adds some customizations to Reveal.


:dev:test is the Polylith portion. :everything:runner is our legacy subproject stuff. :build is our build.clj stuff with :reflect is Stu Halloway's reflector utility to improve datafy/nav for namespaces. :j14 enables some JVM options to improve error reporting (well "improve" is subjective). And :classes adds the classes folder where I have AOT'd code for some dev load improvements (per the page about that -- but I don't really use it much). Normally, I'd also have :add-libs in there for adding dependencies on-the-fly (but recently it has conflicted with so I haven't bothered -- although Alex just merged master to the add-lib3 branch so I may pick that up again).


kool, thanks for the info, I guess starting the REPL from the command line is the way to go, or a clunky jack in if one must


I'm using Emacs and CIDER

👍 3
emacs 3
Matt Ielusic22:08:39

What's a good way to have a def that a component both uses & exposes? The polylith tool readme suggests putting something like (def one-two-three 123) in the interface, but then the component's implementation can't access the value (because of the circular dependency implementation -> interface -> implementation). The obvious thing is to have an interface def that points to an implementation def, but then you can't with-redefs it for testing.


The most common thing I've seen if (def one-two-three 123) in the implementation and then (def one-two-three impl/one-two-three) in the interface. with-redefs can be fairly problematic so I'd question how you get yourself into a situation that needs to redef a def (as opposed to a defn).


If you have a global value, it's going to get compiled into the functions that use it so with-redefs on such a value isn't going to work anyway.

Matt Ielusic22:08:06

There's a test that was written for the non-Polylith repo that with-redefs the var


That's a problem with the current test then I'd say - per above : Def values will be compiled into uses and can't generally be redefd


(sorry for typos - power just went out and I'm on my phone now)

Matt Ielusic22:08:01

I'm not sure what you mean by "global value"? I just have a def for something that depends on how the program was started. And that needs to be tested with multiple values.


can you be a bit more specific as to what the value is/represents/depends on


in the worst case scenario you can just make an explicit test hook in the interface


(def abc impl/abc)

(defmacro with-custom-abc* [new-abc & body]
  `(with-redefs [impl/abc new-abc]
     (do [email protected])))


little * at the end to indicate "experts only, not a part of the interface"

Matt Ielusic22:08:44

My def is for a system property


so its like (def abc (System/getProperty "xyz"))?

Matt Ielusic22:08:17

I don't think that macro quite works? It needs to redef both the core and interface var (as I have discovered the hard way.)


(def abc impl/abc)

(defmacro with-custom-abc* [new-abc & body]
  `(with-redefs [abc new-abc
                 impl/abc new-abc]
     (do [email protected])))


like this?

Matt Ielusic22:08:11

I think so. I almost want to put it in the core file, just to emphasize that it's not really for public use.


you can also make the property derefable


by which i mean


(def abc (delay (System/getProperty "xyz")))


which introduces some indirection, which would let you get away with only redeffing one


so @abc or (abc)


to be clear i'm still not really good/sold on polylith so maybe my advice is tainted


Having a global def just reading off the environment when the ns is loaded is a very bad idea since it'll run when you AOT your code as well as when you require the ns -- that's essentially a side-effect (dependent on the state of the "world") so it should really be a function.

👍 6

(at a bare minimum it should be behind a deref as Ethan suggests but even that is somewhat poor practice IMO)