Fork me on GitHub
#beginners
<
2019-09-17
>
johnjelinek04:09:04

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 [Lsoftware.amazon.awscdk.services.iam.PrincipalBase;

johnjelinek04:09:52

ServicePrincipal extends PrincipalBase

alexmiller04:09:58

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

alexmiller04:09:35

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

alexmiller04:09:18

vectors are java.util.List's already

johnjelinek04:09:33

that works, thanks!

johnjelinek04:09:02

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

alexmiller04:09:38

part of the jvm spec

kailash.subscriptions11:09:33

hi, noob question on https://github.com/bbatsov/clojure-style-guide#oneline-short-fn; does this mean it's okay to have new line between argument vector and a not-so-short function body?

hi13511:09:53

you mean

(defn foo [...]

  (...))
?

kailash.subscriptions11:09:00

no more like

(defn foo
          [..
           ..]

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

kailash.subscriptions11:09:12

^ ignore the indentation

hi13511: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.subscriptions11:09:59

cool, thanks for clarifying! 💯

iagwanderson11:09:37

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?

iagwanderson11:09:14

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

iagwanderson11:09:08

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

moravix13: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)?

borkdude13:09:54

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

borkdude13:09:44

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

moravix13:09:34

Thank you very much for your help! 🙂

studio16:09:33

Does the #shadow-cljs channel exist anymore?

studio16:09:22

Ah, had to search for it 🙂

johnjelinek17:09:05

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

noisesmith17:09:54

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

contato50918: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

hiredman18:09:57

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

contato50918:09:22

In the repl he only execute the first function and stop

hiredman18:09:41

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

hiredman18:09:00

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

contato50918:09:24

yes, is on the (map ...)

contato50918:09:42

(defn execute
   [config]
   (->>
      (:input config)
      (file/get-files-from-a-folder)
      (map #(do-process % config))))

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

(defn -main
   [& args]
   (run))

hiredman18:09:04

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

hiredman18:09:09

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

hiredman18:09:49

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

seancorfield18:09:07

Use run! instead of map, for example.

hiredman18:09:41

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

contato50918:09:48

hmm, I understand

contato50918:09:56

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

hiredman18:09:32

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

hiredman18:09:18

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

contato50918:09:41

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