This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-07
Channels
- # announcements (4)
- # babashka (59)
- # beginners (26)
- # calva (34)
- # clj-kondo (3)
- # cljs-dev (1)
- # clojure (77)
- # clojure-austin (4)
- # clojure-europe (20)
- # clojure-nl (2)
- # clojure-norway (11)
- # clojure-spec (3)
- # clojure-uk (4)
- # clojurescript (103)
- # community-development (2)
- # cursive (15)
- # datalevin (12)
- # datascript (38)
- # datomic (1)
- # deps-new (2)
- # events (3)
- # figwheel-main (6)
- # fulcro (9)
- # honeysql (12)
- # jobs (4)
- # juxt (18)
- # kaocha (19)
- # lsp (42)
- # missionary (2)
- # pathom (14)
- # polylith (6)
- # portal (6)
- # reagent (8)
- # reitit (4)
- # releases (2)
- # shadow-cljs (17)
- # testing (1)
- # tools-deps (50)
- # vim (46)
- # xtdb (12)
Looking at rich4clojure problem 93 partial flatten saw Yunyao and Huahai's solution. I wondered if I drop the let could I expect clojure to optimise (first and (next calls? in
(let [first-col (first coll) rest-col (next coll)]
(def __ (fn pf [coll]
(concat
(if (and (sequential? (first coll)) (not (sequential? (first (first coll)))))
[(first coll)]
(pf (first coll)))
(when (sequential? (next coll))
(pf (next coll))))))
Clojure is not going to optimize that but the JIT is very likely to do so if that code is "hot"
will it matter? hard to say but not too hard to measure to find out (but make sure you use 1000's of iterations to see reliable #s)
Thanks Alex yes that helps. Sorry it was not so much that particular case and optimisation but if I was getting into bad habits by wanting to leave out such (let [ forms. For some reason I always feel the code is read more directly without the let when the bindings are simple?!
how do I view the public vars in an imported namespace? I tried ns-publics
on clojure.java-time
but its telling me it can't even find the namespace despite its being required and I use java-time/local-time
elsewhere.
prometheus-test=> (require 'java-time)
nil
prometheus-test=> (take 3 (ns-publics 'java-time))
([interval #'java-time/interval]
[period #'java-time/period]
[year-month? #'java-time/year-month?])
oh I wasn't quoting it. makes sense. thanks @U11BV7MTK
ah. so clojure.java-time
is the name of the artifact in maven. It has nothing to do with the namespaces contained in it. to download and use the dependency you have to say “give me this dep from maven called clojure.java-time
. You do that with
{:deps {clojure.java-time {:mvn/version "0.3.3"}}}
But using it, we just require the namespaces that we need. This is entirely separate from how we specify the name of the jar this code lives inbut also yes apparently I'm still confused. java-time
is the actual Java time lib and then clojure.java-time
is what? a wrapper?
java.time is the name of a Java package that does date & time stuff, built into the JDK
pro tip: don't use namespace qualifiers that aren't yours (e.g. a leading java or clojure)
java.time
<- java package built into jdk 8+
clojure.java-time
<- name of an artifact in maven with a clojure wrapper around the java.time
package
java-time
<- the primary namespace that the clojure.java-time
maven artifact has
(also; don’t fear just interop’ing with the java.time package. Its a modern API, its fully immutable, It works just like a clojure namespace if you squint your eyes a little. Its the wrapper that sometimes makes it more confusing)
As a formerly heavy user of clojure.java-time
, the only thing it really buys you is easier conversions between types and to/from java.util.Date
. We're migrating off this library and switching to plain Java Time interop.
If you need date/time code that is portable between Clojure and ClojureScript, look at https://github.com/henryw374/cljc.java-time or https://github.com/juxt/tick
(and, yes, the choice of both the Maven coordinates and the single-segment namespace are "bad" for clojure.java-time
)
thanks @U04V70XH6 the CLJS interop will be helpful