Fork me on GitHub
#beginners
<
2022-09-07
>
stantheman15:09:43

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))))))

Alex Miller (Clojure team)16:09:39

Clojure is not going to optimize that but the JIT is very likely to do so if that code is "hot"

Alex Miller (Clojure team)16:09:39

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)

stantheman16:09:15

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?!

Ben Lieberman21:09:44

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.

dpsutton21:09:44

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?])

dpsutton21:09:50

works for me? What are you trying?

dpsutton21:09:07

note i’m using 'java-time. I dont’ have a clojure.java-time namespace

Ben Lieberman21:09:43

oh I wasn't quoting it. makes sense. thanks @U11BV7MTK

dpsutton21:09:45

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 in

Ben Lieberman21:09:20

but also yes apparently I'm still confused. java-time is the actual Java time lib and then clojure.java-time is what? a wrapper?

ghadi21:09:30

it's so poorly thought out

ghadi21:09:54

java.time is the name of a Java package that does date & time stuff, built into the JDK

ghadi21:09:10

whoever wrote this library coopted that name, with a dash

ghadi21:09:23

then stuck a 'clojure' in front of it

ghadi21:09:35

pro tip: don't use namespace qualifiers that aren't yours (e.g. a leading java or clojure)

ghadi21:09:54

endless confusion 🙂

dpsutton21:09:00

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

dpsutton21:09:22

and 100% agreement with @U050ECB92 that you are correct to be confused

🙏 1
Lennart Buit21:09:45

(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)

seancorfield21:09:24

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

seancorfield21:09:14

(and, yes, the choice of both the Maven coordinates and the single-segment namespace are "bad" for clojure.java-time)

Ben Lieberman22:09:26

thanks @U04V70XH6 the CLJS interop will be helpful

cvetan23:09:33

how do I loop some values, populate return array and return it from function

cvetan23:09:41

I can't figure out how to do that

cvetan23:09:25

I found some function online for parsing sitemap, and I am trying to modify that for my use case, I want to return only urls that match certain condition