Curious, can one configure clj
to run some code as soon as a REPL is fired up?
Basically an equivalent to Lein's :init
option
clj -M -e '(some-code)' -r
Nice! Thanks to your answer I checked out https://github.com/practicalli/clojure-deps-edn/blob/65a48e1547d289a3d647d9f32bf3d2cc7fe8d5d3/deps.edn#L479 I wish though that those humongous strings could be expressed as nicely formatted sexprs instead
you can make a function for that somewhere in sourcepath
wdym?
in one of my projects I have dev/src/dev/utils.clj
file with (ns dev.utils)
I also add :extra-paths ["dev/src"]
to one of my alias for dev environment
in that namespace you can create a function
and then from console run it using requiring-resolve
Ah nice! Similarly, my -e
could be a single require
and I do all the work in a proper .clj file
That way I'd skip the last step you describe
clj -A:dev -M -e '((requiring-resolve 'dev/init))' -r
that’s how it could look like in cli
and you can also use -i path
to specify namespace to load as init
Or use -i instead of -e
Oh sorry, slack didn’t show me the last message there :)
How can I access my project’s version at runtime? I’m using deps.edn
This can be expressed as a 5 lines of code in a file that is executed by clj
Ah, it was already mentioned in later discussion
@slack.jcpsantiago does deps.edn have version numbers?
@borkdude Mine straight from clj-new
doesn’t and it seems it’s not supposed to? There is a version in pom.xml
<version>0.1.0-SNAPSHOT</version>
, so I could read this file. I was looking for something that would work like environ
and would read this automatically
@slack.jcpsantiago if using environ the set an Environment variable or create a .properties file for a Java system property
I just inspected clojure.basis to see if my jvm-opts propagated correctly when composing aliases. It did. Neat.
Btw, I stumbled upon this blog https://insideclojure.org/2020/07/28/clj-exec/ but it seems the arguments have been renamed from :fn
and :args
to :exec-fn
and :exec-args
?
Maybe update the blog or is it immutable?
That name change was covered in https://insideclojure.org/2020/09/04/clj-exec/
That blog is a great example of the history of Clojure features and how they evolve during prerelease work. Changing past posts would remove that evolution.
“Don’t believe everything you read on the internet” - Lincoln
It would make sense to add a footnote to an older blog post with a reference to a later update, if one was so inclined.
Well, I’m on vacation :)
Sorry, I should have mentioned that I'm not trying to nudge you or anyone to do that. I do agree that leaving older posts unchanged (except perhaps by addition of such forward-reference footnotes) makes a lot of sense, for anyone wanting to see the history.