This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-31
Channels
- # announcements (6)
- # babashka (40)
- # beginners (6)
- # calva (1)
- # cider (1)
- # clerk (43)
- # clj-kondo (3)
- # clojure (93)
- # clojure-denver (8)
- # clojure-europe (52)
- # clojure-norway (20)
- # clojure-sweden (7)
- # community-development (5)
- # datascript (15)
- # datomic (29)
- # emacs (24)
- # events (15)
- # fulcro (23)
- # graalvm (12)
- # gratitude (1)
- # helix (4)
- # honeysql (4)
- # hoplon (39)
- # hyperfiddle (7)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (26)
- # lambdaisland (3)
- # lsp (6)
- # matcher-combinators (2)
- # matrix (5)
- # meander (39)
- # nrepl (4)
- # nyc (1)
- # off-topic (5)
- # portal (73)
- # practicalli (1)
- # re-frame (2)
- # reitit (22)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (5)
- # sql (17)
- # testing (1)
- # tools-deps (15)
What's the best way to get the current time?
I suppose this question reveals my ignorance as to the relationship between BB and Java in general
Very specifically, I want the current hour as an integer.
> You can still use the regular time APIs Does this mean Java?
Okay let me dig through Oracle docs like the good ol' days 😆
Why is there a .
at the end?
functions vs methods, that just calls the constructor in that example
(-> (.format (new java.text.SimpleDateFormat \"hh\") (java.util.Date.)) parse-long)
(comment
(-> (LocalTime/now) .getHour))
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?
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
Ah gotcha
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!
If there is a strong need for a class, do let us know we would consider it!
Thanks! I just needed LocalTime
🙂
@U058DHAN3UP Just to be clear, LocalTime does work:
user=> (-> (java.time.LocalTime/now) .getHour)
11
Couldn't tell if that was clear or not :)Yup that's what I ended up doing!
(let [hour (.getHour (LocalTime/now))]
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: #'
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")))
Excuse me.
Full stacktrace:
at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:584)
at
at
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)
So somewhere (io/file ..)
is called on a symbol it seems. does this happen only with 180 and not with 179?
Same problem with 179. After the failure in 179 I fell back to 172 and forgot about it.
Worked with 178 - stopped with 179.
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... ✌️
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?
Optionally
{:deps {leifericf/leif-project {:local/root "."}}}
if you want to put your dependencies in deps.edn
, and target babashka and JVM!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:
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.
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.
Thanks, @U058DHAN3UP! I'm using Babashka’s REPL in VS Code via Calva. It's amazing!