Fork me on GitHub
#babashka
<
2023-05-31
>
Colin (fosskers)06:05:33

What's the best way to get the current time?

Colin (fosskers)06:05:57

I suppose this question reveals my ignorance as to the relationship between BB and Java in general

elken06:05:25

You can still use the regular Java date/time APIs

Colin (fosskers)06:05:37

Very specifically, I want the current hour as an integer.

Colin (fosskers)06:05:57

> You can still use the regular time APIs Does this mean Java?

Colin (fosskers)06:05:54

Okay let me dig through Oracle docs like the good ol' days 😆

Colin (fosskers)06:05:50

Why is there a . at the end?

elken06:05:43

functions vs methods, that just calls the constructor in that example (-> (.format (new java.text.SimpleDateFormat \"hh\") (java.util.Date.)) parse-long)

Colin (fosskers)06:05:46

(comment
  (-> (LocalTime/now) .getHour))

elken06:05:11

Yeah or that haha

Colin (fosskers)07:05:10

Follow up: is the reason that I had access to java.time due to bb being compiled with Graal, thereby having access to all of Java?

elken07:05:32

There's only a selection of classes available that have to be worked in manually, so it's not everything but there's a lot. https://github.com/babashka/babashka/blob/master/src/babashka/impl/classes.clj

elken07:05:41

borkdude would be able to explain it better than I 😄

lispyclouds07:05:26

The gist of it is since Graalvm native image is a closed world system, meaning it needs to know of all possibilities to generate native code, hence it needs to be told of what classes could be used. But every class you add adds onto the binary size, a factor we consider very important. Hence we add classes on a need to basis and not everything is supported. Hope that answers it to some extent!

lispyclouds07:05:17

If there is a strong need for a class, do let us know we would consider it!

Colin (fosskers)07:05:39

Thanks! I just needed LocalTime 🙂

borkdude09:05:40

@U058DHAN3UP Just to be clear, LocalTime does work:

user=> (-> (java.time.LocalTime/now) .getHour)
11
Couldn't tell if that was clear or not :)

Colin (fosskers)00:06:18

Yup that's what I ended up doing!

(let [hour (.getHour (LocalTime/now))]

Steffen Glückselig06:05:22

Trying to start a REPL with Version 1.3.180 and Cursive I get a Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #' found for class: clojure.lang.Symbol Babashka seems to be started with bb.exe nrepl-server 54700 - which does not throw when invoked on the CMD... Also: In my preload-Skript I had to change (cp/add-classpath (fs/file dir "src")) to (cp/add-classpath (str (fs/file dir "src")))

borkdude07:05:39

Can you please post stack traces in a thread to not flood the channel?

Steffen Glückselig07:05:52

Excuse me. Full stacktrace: at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:584) at $fn__11487$G__11469__11492.invoke(io.clj:35) at $file.invokeStatic(io.clj:424) at babashka.fs$as_file.invokeStatic(fs.cljc:45) at babashka.fs$as_file.invoke(fs.cljc:42) at clojure.core$map$fn__5935.invoke(core.clj:2772) at clojure.lang.LazySeq.sval(LazySeq.java:42) at clojure.lang.LazySeq.seq(LazySeq.java:51) at clojure.lang.Cons.next(Cons.java:39) at clojure.lang.RT.boundedLength(RT.java:1790) at clojure.lang.RestFn.applyTo(RestFn.java:130) at clojure.core$apply.invokeStatic(core.clj:667) at babashka.fs$file.invokeStatic(fs.cljc:61) at babashka.impl.deps$add_deps$fn__27011.invoke(deps.clj:67) at clojure.core$mapv$fn__8535.invoke(core.clj:6979) at clojure.lang.PersistentVector.reduce(PersistentVector.java:343) at clojure.core$reduce.invokeStatic(core.clj:6885) at clojure.core$mapv.invokeStatic(core.clj:6970) at babashka.impl.deps$add_deps.invokeStatic(deps.clj:65) at babashka.main$exec$fn__31774.invoke(main.clj:870) at clojure.lang.AFn.applyToHelper(AFn.java:152) at clojure.lang.AFn.applyTo(AFn.java:144) at clojure.core$apply.invokeStatic(core.clj:667) at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990) at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990) at clojure.lang.RestFn.invoke(RestFn.java:425) at babashka.main$exec.invokeStatic(main.clj:822) at babashka.main$main.invokeStatic(main.clj:1165) at babashka.main$main.doInvoke(main.clj:1122) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invokeStatic(core.clj:667) at babashka.main$_main.invokeStatic(main.clj:1198) at babashka.main$_main.doInvoke(main.clj:1190) at clojure.lang.RestFn.applyTo(RestFn.java:137) at babashka.main.main(Unknown Source)

borkdude07:05:39

So somewhere (io/file ..) is called on a symbol it seems. does this happen only with 180 and not with 179?

Steffen Glückselig08:05:33

Same problem with 179. After the failure in 179 I fell back to 172 and forgot about it.

borkdude08:05:41

Can you check the latest version which didn’t work for you?

borkdude08:05:01

Sorry, which did work for you

Steffen Glückselig08:05:27

Worked with 178 - stopped with 179.

borkdude09:05:47

Do you have a repro with bb only, without cursive perhaps?

borkdude09:05:36

also running bb --debug nrepl-server may give you more hints

Steffen Glückselig13:06:42

I couldn't reproduce the exception with bb --debug nrepl-server or some other invocations I've tried. I've found the problem, though. I had _:paths_ [src test] in my bb.edn, changing it to :paths ["src" "test"] got me rid of the problem. I am now on version 1.3.181... ✌️

🎉 2
leifericf11:05:19

This might be a "dumb" question, but, what does a minimal bb.edn look like? I imagine the only required dependency is to Babashka itself, and maybe Clojure. But I couldn't find a barebones example in the Babashka book. I just put a pair of empty curly braces (`{}`) in there, which seems to appease the REPL, but I'm not sure whether that is "correct." Do I need to add references to some version of Babashka and/or Clojure?

borkdude11:05:42

Yes, {} is the minimal bb.edn

🙌 2
☝️ 4
teodorlu12:05:10

Optionally

{:deps {leifericf/leif-project {:local/root "."}}}
if you want to put your dependencies in deps.edn, and target babashka and JVM!

👍 4
borkdude12:05:02

or if you want to write bb-or-jvm library

4
avfonarev14:05:52

Same for deps.edn, by the way. The minimal one is {}.

👍 2
leifericf14:05:04

For context, I'm preparing for an internal workshop on functional programming using Clojure and Babashka as the vehicle for learning. I'm creating a barebones Git repo as a kind of "template" for our in-house scaffolding tool, so that other developers, who have zero experience with Clojure, can have a starting point to build their utils library over time. Are there any libraries that “everyone” tends to use, say, 80% of the time, that I could include in the said “template” as examples? If that would even be a reasonable thing to do; I'm not sure. :thinking_face:

👍 2
teodorlu18:05:14

I've found the list of bundled libraries from the book (https://book.babashka.org/#libraries) plus the babashka toolbox (https://babashka.org/toolbox/) to be helpful! If I have further questions about how to do something specific, I usually ask in #CLX41ASCS.

👀 2
Colin (fosskers)00:06:55

Lightly related: if you just want to dev quickly on a bb script but not bother with any external config, bb has its own nrepl: bb nrepl-server that can be connected to manually from your editor.

👍 4
leifericf05:06:45

Thanks, @U058DHAN3UP! I'm using Babashka’s REPL in VS Code via Calva. It's amazing! calva

👍 2