Fork me on GitHub

how do I cast this collection into a Java List of objects?

(new CompositePrincipal [(new ServicePrincipal "")
                         (new ServicePrincipal "")])

Execution error (ClassCastException) at user/eval5850 (REPL:1).
clojure.lang.PersistentVector cannot be cast to [;


ServicePrincipal extends PrincipalBase

Alex Miller (Clojure team)04:09:58

that's not a Java List, it's a Java array

Alex Miller (Clojure team)04:09:35

(CompositePrincipal. (into-array PrincipalBase [(ServicePrincipal. "") (ServicePrincipal. "")]))

Alex Miller (Clojure team)04:09:18

vectors are java.util.List's already


that works, thanks!


[L...; is such a weird notation for array

Kailash K11:09:33

hi, noob question on; does this mean it's okay to have new line between argument vector and a not-so-short function body?

Iwo Herka11:09:53

you mean

(defn foo [...]


Kailash K11:09:00

no more like

(defn foo

  (....large block...))

Kailash K11:09:12

^ ignore the indentation

Iwo Herka11:09:11

imvho that's ugly. as per splitting the argument vector, never saw a need for it. if function takes a lot of args its probably better to accept a map

Kailash K11:09:59

cool, thanks for clarifying! 💯


hi people, I have a question about datomic. Imagine that I have an entity that has its values updated daily by a computation. I can manage to perform the calculation everytime an user asks for the data at a specific date. However, I can store this calculation daily in an entity in datomic and just query the past-entries when asked. There is any problem from modeling perspective using datomic this way?


this calculations can change over time [the formula] and would be nice to have it stored as well.


they are very error-prone and most of the time, all the stakeholders of this process waste some weeks arguing who did the correct computation, when and why

Keyser Söze13:09:03

Hi, I asked the same question in the Clojure IRC channel but I accidentally disconnected before I saw any answers... 😞 Say I have a lazy sequence S. If I call (nth S 100000), is it the case that elements 1 to 99999 have been realized and placed on the heap? Thereby, allowing me to fetch the result directly from the heap when I subsquently call, say, (nth S 50000)?


if it's a lazy-seq all the elements up to the 100000th will be realized, correct


if you want nth to be fast the next time, you probably want to put it in an indexed collection like vector

Keyser Söze13:09:34

Thank you very much for your help! 🙂


Does the #shadow-cljs channel exist anymore?


Ah, had to search for it 🙂


@moravix: you could also memoize your answer if you don't want to not do a lazy sequence


also it's important to distinguish the cost of producing items vs. the cost of traversal - either way you only pay for realizing the items once as long as you actually use a lazy-seq and not eg. eduction

Roger Amorin Vieira18:09:39

Hey, I finish a project using repl to test, now when I do lein run i get a different result from lein repl -> (-main), someone can say why this happen? And how do I fix this


what is the result when you call -main at the repl?

Roger Amorin Vieira18:09:22

In the repl he only execute the first function and stop


my guess is you are doing something like (map some-fn ...) and that is being returned from -main, and the repl printing the result is forcing the lazy seq returned from -main


and when you run it outside the repl, there is no printing there that forces the lazy seq

Roger Amorin Vieira18:09:24

yes, is on the (map ...)

Roger Amorin Vieira18:09:42

(defn execute
      (:input config)
      (map #(do-process % config))))

(defn run
   (map execute (get-config))) ; STOPS HERE

(defn -main
   [& args]


map returns a lazy sequence, meaning it only does stuff if you do stuff with the resulting sequence, so it is not well suited to things where you don't care about or use the result


right, -main returns the lazy sequence, the lazy sequence is realized in the repl (read, eval, print, loop) when the returned value is printed out, when you run from not in the repl, there is no print step to force the final result


so you need to either explicitly force the result yourself, or use some other non-lazy thing


Use run! instead of map, for example.


you also have two layers of laziness (because of the two levels of maps), so you will likely need to make sure they are both realized to get the behavior you want

Roger Amorin Vieira18:09:56

So every map that I have, I need to replace to force the result, Am I right?


if you are using them for side effects, and not using the result, you do, but that is generally a bad way to use map


if you are just going to throw the result away run!, as mentioned, is a pretty good drop in replacement for map

Roger Amorin Vieira18:09:41

I think now is working, thanks so much. Problem solved, but I will study more about this thing