Fork me on GitHub
#babashka
<
2023-06-26
>
keychera06:06:12

if I want to share my bb project for others to use, using:

bb -Sdeps '{:deps {some.deps {:git/tag "some-tag" :git/sha "some-sha"}}}' -m main ...
do you need JVM to run this? somehow I am not sure because to make my project be able to be used like this, I have to add deps.edn to the project, which made me think JVM would be involved

borkdude07:06:25

You don't need a JVM, except for downloading your project as a dependency, just once

borkdude07:06:32

Just like any other deps in bb.edn

keychera08:06:28

I see, JVM is still needed in this case. is there any alternative to share babashka project like this? or I better convert my script to one or two files and use raw github links so I can share to my colleague without them having to setup JVM? in my case, the project is not that big and purely babashka so the single script is still feasible

borkdude08:06:14

you can use the uberscript or uberjar packaging to distribute it without a JVM download

borkdude08:06:21

bb uberjar.jar bb uberscript.clj

borkdude08:06:42

and you can use bbin to install the uberjar without a jvm download

borkdude08:06:47

as a system-wide script

keychera08:06:57

oh nice! I will look into them, sharing the jar file would be probably the simplest

leifericf11:06:53

When I have a Java object, for example, an instant of java.time.ZonedDateTime, what is the cleanest way to see what members it has available? This seems to get the job done:

(defn inspect-object [obj]
  (let [class (.getClass obj)
        methods (.getDeclaredMethods class)
        fields (.getDeclaredFields class)]
    (println "Methods:")
    (doseq [method methods]
      (println (.getName method)))
    (println "Fields:")
    (doseq [field fields]
      (println (.getName field)))))

(defn now []
  (java.time.ZonedDateTime/now))

(inspect-object (now))
Output:
Methods:
range
ofLocal
withZoneSameInstant
toOffsetDateTime
withZoneSameLocal
[...]
Fields:
nil
But I suspect there's a more straightforward approach of which I'm not yet aware.

borkdude11:06:21

Can you please limit long posts in this channel by e.g. using a gist or post the long output in a thread?

👍 2
borkdude11:06:17

This might work too:

bb -e "(require '[clojure.datafy]) (clojure.datafy/datafy java.time.ZonedDateTime)"

🙇 2
👍 4
leifericf11:06:27

Oh, wow. That's amazing! It worked fantastically.

Colin (fosskers)02:06:28

This language keeps impressing me!

leifericf06:06:09

I thought I would need to bust out clojure.reflect for this. Alas, that shiny object (pun intended) will need to wait for its glory day. I guess clojure.datafy makes use of that under the hood :thinking_face:

leifericf06:06:54

Wow, the implementation is datafy is remarkably terse and clean. https://github.com/clojure/clojure/blob/master/src/clj/clojure/datafy.clj