Fork me on GitHub
#clojure
<
2022-06-04
>
pinkfrog06:06:13

I install java with asdf. I am constantly seeing this warning, which is a bit annoying though:

Warning: environ value /Users/pinkfrog/.asdf/installs/java/zulu-17.30.15 for key :java-home has been overwritten with /Users/pinkfrog/.asdf/installs/java/zulu-17.30.15/zulu-17.jdk/Contents/Home

p-himik06:06:03

It comes from this library: https://github.com/weavejester/environ And it complains that your JAVA_HOME environment variable does not point to the Java that you're actually running.

pinkfrog07:06:45

Guess you searched the keyword ” environ value” ?

p-himik07:06:56

I've seen that warning in one of the projects I'm working on. Just searched the contents of its classpath.

pinkfrog07:06:59

btw, how do you address it?

p-himik07:06:11

I don't, I don't really care. If you do, just set JAVA_HOME to the right value when starting Java.

pinkfrog07:06:36

Does Clojure have a function that acts like ignore which takes a variadic number of arguments and does nothing?

pinkfrog07:06:06

Maybe (`constantnly nil)`.

👍 3
seancorfield21:06:16

comment 😁

😅 1
borkdude09:06:45

Anyone familiar with leiningen and setting a clojure version outside of a project? https://clojurians.slack.com/archives/C0AB48493/p1654334489881789

pinkfrog12:06:30

Hi guys, I’d like to know the idiomatic way of writing the following function

(defn- path-to-ns
  [path]
  ;; "src/foo/bar" -> "foo.bar.main"
  (let [path (str path "/main")
        idx (inc (str/index-of path "/"))
        path (subs path idx)
        path (str/replace path #"/|-" {"/" "."
                                       "-" "_"})]
    path))
(path-to-ns "src/foo/bar")

pinkfrog12:06:36

I feeling like the use of let here looks coarse. But I dunno a better way.

Jason13:06:53

(defn- path-to-ns
  [path]
  ;; "src/foo/bar" -> "foo.bar.main"
  (let [path (str path "/main")
        idx (inc (str/index-of path "/"))]
      (-> (subs path idx)
          (str/replace #"/|-" {"/" "."
                                       "-" "_"}))

(path-to-ns "src/foo/bar")
Sorry about formatting, I think this is marginally better

thanks3 1
Martin Půda13:06:37

My attempt:

(defn path-to-ns [path]
    (->> (-> (str/replace path #"-" "_")
             (str/split #"/")
             (conj "main")
             rest)
         (str/join ".")))

thanks3 1
Célio15:06:23

Found something curious today, pop works for vector and list but it doesn't work for java.lang.Cons or clojure.lang.LazySeq . Is this by design? I guess it makes sense if it's by design since pop is supposed to work on "closed" data structures as opposed to "open" things that can return an infinite number of elements like lazy seqs, etc.

user=> (pop [1 2 3])
[1 2]
user=> (pop '(1 2 3))
(2 3)
user=> (pop (cons 1 '(2 3)))
Execution error (ClassCastException) at user/eval5 (REPL:1).
class clojure.lang.Cons cannot be cast to class clojure.lang.IPersistentStack (clojure.lang.Cons and clojure.lang.IPersistentStack are in unnamed module of loader 'app')
user=> (pop (lazy-seq (cons 1 (lazy-seq nil))))                        
Execution error (ClassCastException) at user/eval7 (REPL:1).
class clojure.lang.LazySeq cannot be cast to class clojure.lang.IPersistentStack (clojure.lang.LazySeq and clojure.lang.IPersistentStack are in unnamed module of loader 'app')

bronsa15:06:29

the docstring is pretty explicit about what it supports

bronsa15:06:54

For a list or a queue [..] for a vector [..]

bronsa15:06:07

a cons or a lazy-seq is not either of those

Célio15:06:43

Thanks, I think sometimes we conflate those things with lists due to how they operate similarly in some aspects, or how similar they look as outputs.

bronsa15:06:18

yeah, I get it. you should remember that all those things are seqs, not necessarily lists 🙂

💯 1
dpsutton15:06:45

I suspect this is because a cons or lazy seq can go over a collection that peek/pops differently right? You’re “breaking” the data structure (peek [1 2 3]) -> 3 (peek (list 1 2 3)) -> 1 so if you could (peek (cons 0 [1 2 3])) you’ve created a mismatch and scrambled your queue/stack. The cons would add the 0 at the “wrong” end

👀 1
2