This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-17
Channels
- # announcements (2)
- # aws (7)
- # beginners (46)
- # cider (15)
- # clj-kondo (24)
- # cljs-dev (3)
- # clojure (46)
- # clojure-dev (34)
- # clojure-europe (7)
- # clojure-italy (7)
- # clojure-nl (10)
- # clojure-norway (15)
- # clojure-spec (5)
- # clojure-uk (42)
- # clojuredesign-podcast (1)
- # clojurescript (79)
- # clr (3)
- # core-async (1)
- # cursive (45)
- # data-science (1)
- # datomic (4)
- # fulcro (17)
- # funcool (14)
- # gorilla (2)
- # graphql (30)
- # jackdaw (5)
- # jobs-discuss (8)
- # joker (4)
- # lein-figwheel (1)
- # off-topic (48)
- # pedestal (26)
- # re-frame (36)
- # reagent (18)
- # reitit (6)
- # remote-jobs (4)
- # shadow-cljs (115)
- # tools-deps (62)
- # vim (12)
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;
ServicePrincipal
extends PrincipalBase
that's not a Java List, it's a Java array
(CompositePrincipal. (into-array PrincipalBase [(ServicePrincipal. "
vectors are java.util.List's already
that works, thanks!
[L...;
is such a weird notation for array
part of the jvm spec
hmm ... ok
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?
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
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
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 you want nth to be fast the next time, you probably want to put it in an indexed collection like vector
Thank you very much for your help! 🙂
@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
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
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
yes, is on the (map ...)
(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))
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
hmm, I understand
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
I think now is working, thanks so much. Problem solved, but I will study more about this thing