This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-17
Channels
- # adventofcode (3)
- # announcements (1)
- # babashka (25)
- # beginners (55)
- # calva (12)
- # cider (40)
- # clj-kondo (13)
- # clojure-australia (2)
- # clojure-dev (11)
- # clojure-europe (67)
- # clojure-france (6)
- # clojure-nl (16)
- # clojure-uk (9)
- # clojuredesign-podcast (9)
- # clojurescript (17)
- # conjure (7)
- # cursive (3)
- # datomic (3)
- # emacs (8)
- # figwheel-main (7)
- # fulcro (21)
- # google-cloud (21)
- # graphql (8)
- # helix (1)
- # honeysql (32)
- # instaparse (2)
- # jobs (2)
- # jobs-discuss (2)
- # meander (80)
- # mount (1)
- # off-topic (25)
- # pathom (31)
- # polylith (1)
- # rdf (24)
- # re-frame (21)
- # reagent (29)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (16)
- # slack-help (6)
- # sql (5)
- # tools-deps (23)
- # uncomplicate (2)
- # wasm (2)
- # xtdb (4)
Hello!
On Clojure/JVM, I can evaluate clojure.lang.PersistentVector
, and get a java class. On Babashka, I cannot. See attached error message.
@beoliver and I could "just use symbols" instead. But I would like to ask why this behavior is different from clj to bb first.
Any advice?
@teodorlu This is because not all classes are "mapped" into bb because this takes extra space. Most interfaces are available though, like clojure.lang.IPersistentVector
Hi - jumping in as @teodorlu mentioned… Good to know about the interfaces. the concrete example of the issue we are trying to solve is in porting the following pattern (The following is a simplified example)
we could re-write and use map?
string?
etc or use interfaces - but the ability to use sets of types makes the algorithm fairly clean :thinking_face:
Maybe you could implement this like (every? #(instance? clojure.lang.IPersistentMap %) ...)
instead. This will avoid relying on concrete classes
Or you can make a function that translates your thing to a keyword based on a predicate
> Or you can use hierarchies maybe as well (`isa?`, `derive` , etc)
I think we should be able to get the same performance guarantees as we have right now with a custom hierarcy, and derive
calls. Good idea. As ben says, we might just go for a simple solution, though.
@borkdude thanks for the help!
I think I could support instance checks for the concrete classes as well in bb. You could post an issue for next time you need it
the only reason for sets was to reduce the search space but chances are that every?
will return quickly on error. for the other usecase we can rewrite it as
(defn partition-by-type [items]
(let [key-fn (juxt number? string? boolean? vector? map?)]
(vals (group-by key-fn items))))
> (partition-by-type [1 "2" 2 "3" true ])
([1 2] ["2" "3"] [true])
Both clojure.lang.IPersistentVector
and clojure.lang.IPersistentMap
are available for instance checks, protocols, etc
In honor of @borkdude half-life, here is a single multifaceted form to celebrate:
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {cljc.java-time/cljc.java-time {:mvn/version "0.1.12"}}})
(require '[cljc.java-time.local-date :as ld])
(require '[cljc.java-time.temporal.chrono-unit :as cu])
(let [min-bork "1981-02-08"
max-bork (int (* 365.25 80.6)) ; NL male, round down
all-bork 100]
(defn borkdays [] (cu/between cu/days (ld/parse min-bork) (ld/now)))
(defn borkcal []
(format "Borkdude is %d days old, expiration in %d days. (%.2f%% remaining)"
(borkdays)
(- max-bork (borkdays))
(double (- all-bork (* all-bork (/ (borkdays) max-bork)))) ))
(println (borkcal)) )
It's early days, but this is all of the boilerplate you need to deploy bb to lambda, as a docker image; https://gist.github.com/lukaszkorecki/a1fe27bf08f9b98e9def9da4bcb3264e - works in the emulator at least 😉 Once I got it all working down to deploying to AWS, I'll open source a sample repo along with Terraform manifests required to deploy this
Whats the best way to determine if a script is being executed vs say imported or REPLed? Use the file variable?