Fork me on GitHub
#clojure
<
2019-02-10
>
theeternalpulse10:02:14

is there anything like a static analysis tool to add type hints to a clojure file?

jlmr13:02:16

Hi! The following code:

(ns my-ns
        (:refer-clojure :exclude [def]))

   (alias 'c 'clojure.core)

   (c/def test 1)
Gives an error: RuntimeException No such var: c/def. What am I doing wrong here?

Jimmy Miller14:02:17

If you take a look at the publics for clojure.core you will see that def is not included.

(sort (keys
       (ns-publics 'clojure.core)))
That's because def is actually a special form. https://clojure.org/reference/special_forms#def

joelsanchez15:02:08

:refer-clojure is outside ns

jlmr16:02:14

You’re right of course, i mistyped it in Slack, but it’s correct in my code

Bravi18:02:09

hi everyone. I have a list of lists -

((1 2 3) (1 0 6) (3 9 8))
and I’d like to interleave these and put them in lists again, so basically my end result to be
((1 1 3) (2 0 9) (3 6 8))
I’m a bit stuck, because I ended up with something like
(apply list (apply interleave my-list))
and it obviously doesn’t work

shaun18:02:40

@bravilogy (->> (apply interleave my-list) (partition 3))

Bravi18:02:19

ah right! thanks @shaun

shaun18:02:43

you're welcome

andy.fingerhut18:02:48

An alternative that should work for more then 3 lists of lists (I am not saying shaun's does not -- I just suspect perhaps maybe it is limited to that because of the (partition 3)):

andy.fingerhut18:02:50

user=> (apply map list '((1 2 3) (1 0 6) (3 9 8)))
((1 1 3) (2 0 9) (3 6 8))

👍 10
Bravi18:02:42

👍 nice one. they both work actually 🙂 I love the fact that there are many different ways you can approach things

dominicm20:02:50

Why does using a nested j.u.H cause a reflection warning? How can I do this properly?

(defn foo
  []
  (java.util.HashMap.
    {"baz" (java.util.HashMap.
             {"foo" "bar"})}))
Reflection warning, NO_SOURCE_PATH:3:3 - call to java.util.HashMap ctor can't be resolved.

dominicm21:02:50

I mean, I can reduce-kv, but other than that 🙂

dpsutton21:02:47

there are two single arg constructors. need to indicate which one?

dpsutton21:02:39

not sure how to indicate HashMap(Map<? extends K,? extends V> m).

Alex Miller (Clojure team)21:02:50

I don’t think that’s it

Alex Miller (Clojure team)21:02:03

specifically the inner one does not reflect, only the outer one

Alex Miller (Clojure team)21:02:06

TBH, I can’t explain that without digging into the compiler more

erwinrooijakkers21:02:45

@bravilogy another one 😉

(require '[core.matrix :as matrix])
(matrix/transpose '((1 2 3) (1 0 6) (3 9 8)))
;; => ((1 1 3) (2 0 9) (3 6 8))

👍 10