This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-23
Channels
- # babashka (22)
- # beginners (8)
- # calva (7)
- # clj-kondo (65)
- # cljdoc (9)
- # cljsrn (1)
- # clojure (53)
- # clojure-australia (4)
- # clojure-europe (49)
- # clojure-gamedev (2)
- # clojure-italy (13)
- # clojure-nl (1)
- # clojure-spec (19)
- # clojure-uk (4)
- # clojurescript (48)
- # clojureverse-ops (1)
- # core-async (3)
- # css (2)
- # cursive (15)
- # datomic (6)
- # degree9 (2)
- # depstar (4)
- # emacs (2)
- # find-my-lib (1)
- # fulcro (16)
- # graalvm (11)
- # gratitude (1)
- # honeysql (9)
- # introduce-yourself (2)
- # jobs (1)
- # joker (2)
- # livestream (2)
- # malli (16)
- # nbb (4)
- # news-and-articles (2)
- # off-topic (1)
- # pathom (7)
- # polylith (10)
- # practicalli (1)
- # re-frame (7)
- # reitit (1)
- # releases (3)
- # remote-jobs (1)
- # rewrite-clj (19)
- # shadow-cljs (10)
- # tools-build (1)
- # tools-deps (9)
- # uncomplicate (1)
- # vim (3)
- # xtdb (44)
Just starting out with Babashka. This probably has been asked before: Is it possible for me to use java.util Calendar Date TimeZone
and java.text.SimpleDateFormat
? I looked at pods and bb.edn and didn't find what I was looking for or at least not in a straight forward way.
I guess the most straight forward way I was expecting is for it to be part of the babashka binary itself. What is the simplest alternative to use it without spinning up a JVM (via pods?).
java.time classes are support, you can use those:
user=> (import '(java.time.format DateTimeFormatter) '(java.time LocalDateTime))
java.time.LocalDateTime
user=> (.format (DateTimeFormatter/ofPattern "yyyy-MM-dd") (LocalDateTime/now))
"2021-08-23"
The java.time APIs are slick. Used to convert everything to epoch timestamps and work on them and format them back. Now I can directly work with what I want, example just the date. TIL about this.
Is there a way to have babashka's -I
flag use the default tagged-literal
function as a fallback?
example:
❯ echo '{:foo "bar"}' | bb -I -O '(map :foo *input*)'
"bar"
with a tagged literal:
❯ echo '{:foo #some-tag "bar"}' | bb -I -O '(map :foo *input*)'
----- Error --------------------------------------------------------------------
Type: clojure.lang.EdnReader$ReaderException
Message: java.lang.RuntimeException: No reader function for tag some-tag
Location: <expr>:1:1
----- Context ------------------------------------------------------------------
1: (map :foo *input*)
^--- java.lang.RuntimeException: No reader function for tag some-tag
----- Stack trace --------------------------------------------------------------
clojure.core/map - <built-in>
user - <expr>:1:1
I tried using set!
to change *data-readers*
:
❯ echo '{:foo #some-tag "bar"}' | bb -I -O '(set! *data-readers* {:default tagged-literal})(map :foo *input*)'
----- Error --------------------------------------------------------------------
Type: clojure.lang.EdnReader$ReaderException
Message: java.lang.RuntimeException: No reader function for tag some-tag
Location: <expr>:1:48
----- Context ------------------------------------------------------------------
1: (set! *data-readers* {:default tagged-literal})(map :foo *input*)
^--- java.lang.RuntimeException: No reader function for tag some-tag
----- Stack trace --------------------------------------------------------------
clojure.core/map - <built-in>
user - <expr>:1:48
I would like to work on this, can you give me a hint as to where to start looking for relevant code?