beginners

2025-10-22T00:57:58.380479Z

is it possible to print out the project version with lein? project.clj has (defproject my.package/foo "0.1.2-SNAPSHOT" ...) and i'd like to be able to say lein X and print out 0.1.2-SNAPSHOT

seancorfield 2025-10-22T01:34:10.842829Z

Per the Leiningen FAQ, you can do this:

(!2006)-> lein repl
...
user=> (require '[ :as io])
nil
user=> (with-open [pom-properties-reader (io/reader (io/resource "META-INF/maven/slingshot/slingshot/pom.properties"))]
  #_=>   (doto (java.util.Properties.)
  #_=>     (.load pom-properties-reader)))
{"groupId" "slingshot", "artifactId" "slingshot", "version" "0.12.2", "revision" "b0875f5caee1ebb069d4d799b71af976e04f21d8"}
user=>
(I ran this in an old Slingshot repo -- adjust the group/artifact as needed)

seancorfield 2025-10-22T01:34:21.360259Z

https://leiningen.org/faq.html

2025-10-22T01:35:07.673709Z

i saw that, was hoping for an easier command. thanks

2025-10-22T01:35:20.779049Z

something i can call from the command line in a bash script

seancorfield 2025-10-22T01:35:54.102309Z

Unfortunately, you can't -e eval arbitrary code with lein run

seancorfield 2025-10-22T01:37:16.437309Z

There may be a plugin you can add to your user profile...? I've hardly used lein since 2015 so I'm a bit hazy.

Bob B 2025-10-22T04:13:00.584309Z

> lein update-in :version println "!"
0.1.0-SNAPSHOT !
the extra arg seems to be necessary, and it's completely not what update-in was meant to do, but hey, I've got more cursed stuff than this running in prod, so 🤷

🎉 4
2025-10-22T04:31:10.143069Z

look at that!

seancorfield 2025-10-22T14:00:37.561509Z

Haha... that's wild! Slick...

frankitox 2025-10-22T17:39:04.055969Z

Hello 👋 I'd like to record every call to a certain function, eg: datomic.api/q. So I was thinking of wrapping it via with-redefs-fn, something like this

frankitox 2025-10-23T17:01:56.445339Z

Nice 😄 works beautiful!!

Harold 2025-10-23T17:26:31.291689Z

🤭

frankitox 2025-10-22T17:41:10.455439Z

(let [f @#'clojure.core/first]
  (with-redefs-fn {#'clojure.core/first
                   (fn [coll]
                     ;; My custom code
                     (println "Hi")
                     (f coll))}
    (fn []
      (first [1 2]))))
Which is giving me a StackOverflowError error

frankitox 2025-10-22T17:41:55.454679Z

Is it possible to reference the old var definition from the replacement?

seancorfield 2025-10-22T17:45:08.890609Z

clojure.core is AOT compiled and direct-linked, so you can't reliably redefine its functions.

seancorfield 2025-10-22T17:45:53.049409Z

(and I strongly suspect with-redefs-fn is not thread-safe -- just like with-redefs -- and should not be used in any production code, and should only be used with great care in tests)

2025-10-22T17:53:17.615389Z

hi! If it is for debugging purposes in dev there is https://www.flow-storm.org/, which doesn't require any modification to your codebase and can record/inspect everything.

Harold 2025-10-22T18:44:31.309029Z

If it's your code that's doing the calling, you could also just write a helper/wrapper function and call that instead.

frankitox 2025-10-22T21:31:33.417769Z

Oh, that's unfortunate. Yep, the function is not mine and I'm not running this on prod 😅

frankitox 2025-10-22T21:32:13.115659Z

Maybe I'll take a peek at flowstorm, I was expecting to do this just from the REPL

frankitox 2025-10-22T21:32:15.342589Z

Thanks!!

frankitox 2025-10-22T21:33:22.162499Z

(the function I want to redefine is datomic.api/q, which I assume is probably AOT compiled too)

Harold 2025-10-22T21:35:51.246719Z

You can do what you want, hang on...

frankitox 2025-10-22T21:36:43.234349Z

Haha no rush!

Harold 2025-10-22T21:58:47.930199Z

Handle with care...

user> (defn do-some-query!
        []
        (-> (d/q '[:find ?e
                   :where [?e :db/txInstant]]
                 db)
            (first)))
#'user/do-some-query!
user> (do-some-query!)
[13194143730722]
user> (let [old-q @#'datomic.query/q]
        (with-redefs [datomic.query/q (fn [& args]
                                        (println  "we in there...")
                                        (let [res (apply old-q args)]
                                          (println "we outta there...")
                                          res))]
          (do-some-query!)))
we in there...
we outta there...
[13194143730722]

Harold 2025-10-22T21:59:57.833849Z

Something similar could be done with alter-var-root! as well, if one were in the mood for a more permanent change.

💡 1
Harold 2025-10-22T22:01:32.137119Z

We were just discussing today how delightful it is that so little of datomic is direct linked. 🤭