This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-04
Channels
- # admin-announcements (6)
- # alda (1)
- # announcements (3)
- # aws (4)
- # beginners (233)
- # boot (82)
- # cider (11)
- # cljsjs (21)
- # cljsrn (7)
- # clojure (262)
- # clojure-japan (1)
- # clojure-russia (129)
- # clojure-sg (2)
- # clojure-taiwan (2)
- # clojurecup (23)
- # clojurescript (162)
- # clojurex (3)
- # core-async (18)
- # cursive (81)
- # datavis (183)
- # datomic (23)
- # emacs (2)
- # funcool (25)
- # ldnclj (82)
- # lein-figwheel (3)
- # om (196)
- # onyx (74)
- # parinfer (7)
- # portland-or (12)
- # re-frame (60)
- # reagent (48)
- # slack-help (1)
- # yada (9)
how come this macro doesn’t work?
(defmacro rev-ord [& args]
`(let [op# ~(last args)]
(apply (resolve op#) ~(quote 3) ~(quote 9))))
(rev-ord [12 21] ‘+)
I get
java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long
RT.java:528 clojure.lang.RT.seqFrom
RT.java:509 clojure.lang.RT.seq
RT.java:648 clojure.lang.RT.cons
core.clj:29
You'll see that you have (apply (resolve op) 3 9)
and apply
expects the last argument to be a sequence
(into [] (map (fn [sched] (get sched "schedule_id")) schedulelist))
where schedulelist
is a vector of maps {:schedule_id id}
oke have you tried then `(get "schedule_id" sched) I think you have to order wrong in your get
That whole thing is producing nil
? Seems odd since even if map
produces an empty sequence you'd get []
not nil
well it doesn't seem to be showing anything, I have the whole thing wrapped into (str )
Since map
over schedulelist
must produce a sequence with the same number of elements.
If I have this sort of problems I try to make the code first smaller to see what each part produces
Uncaught TypeError: Cannot read property 'cljs$core$IFn$_invoke$arity$1' of null
well that explains a lot
It was my first attempt at it then I decided to just do (map #(get % "schedule_id") schedulelist)
instead
How canI desctruct this the best `[ { :account bank :withdraw 200} {:account cash :deposit 200} ]' so account1 has the value bank. amount the withdraw amount , account2 cash and amount2 the deposit value
You can't give things arbitrary names like that. What's the problem you're really trying to solve?
what I try to do is that I can withdraw money from my bank and deposit it into my cash
Not really. Not sure what restructuring has to do with it. And it's way past bedtime here anyway.
I'm not saying it will be easier, but it could be. I'm not fully familiar with refs though.
I am doing the 4 clojure stuff. shouldn't this be true? (= '(1 4 7 10 13) (take 5 (iterate #(+ 3 %) 1)))
what is wrong here (reduce (fn[acc it] (+ acc (get transactions :withdraw) )) (filter #(contains? % :withdraw) transactions))
What I try to do is to sum all the values of :withdraw in for example this vector [ { :account cash :withdraw 100} { :account cash :withdraw 200} ]
I have now this : (reduce (fn[acc it] (+ acc (get transactions :withdraw) )) (filter #(contains? % :withdraw) transactions)))
when I call it with (process-user-action [ {:account bank :withdraw 200} ] )
I was expecting to see 200 but I see this as output : `=> {:account #object[clojure.lang.Atom 0x629fee00 {:status :ready, :val {:amount 0}}], :withdraw 200}'
(reduce + (map :withdraw [ { :account :cash :withdraw 100} { :account :cash :withdraw 200} ]))
and accounts looks like this : [{:account #object[clojure.lang.Atom 0x7225704a {:status :ready, :val {:amount 0}}], :withdraw 200}]
oke, now with this code : (map (fn[transactions] (get transactions :withdraw)) transactions ) )
I see this answer (200) so almost good
Aside from Luminus is there any other considerable effort in creating a standard way of doing web development?
Never know that I would be so difficult to get the total amount of for example all the items which has :withdraw in it
@grounded_sage: I haven't seen any that's currently maintained aside from Luminus. I'd guess most people who don't use Luminus work things out on their own (I'm doing my web apps from scratch)
The part if I have this '[ {:account cash :withdraw 200} {:account bank :withdraw 100} I see 300
It's a shame. I get that composing libraries together yourself is a lot more powerful. However for people that are looking to get up and running and building stuff for people to make money it's quite daunting having to figure it all out yourself. I'm currently weighing up learning Elixir and the Phoenix Framework vs using Clojure. I much prefer the Clojure language but there is a huge benefit with people all rallying behind a standard way of doing things.
Your entire transaction looks like this: [ {:account cash :withdraw 200} {:account bank :withdraw 100} ]
right?
You want to return 300
which is the sum of all values in the :withdraw
key as you are withdrawing
from two accounts, cash
and bank
First of all, you are on the right track that you should probably pass in maps of the same structure.
It's implied if you are withdraw
with cash and bank account, you are taking from the bank
correct , so if someone takes 100 euro from the bank and puts 80 in cash there wll be a error
Hmm, let's think about that for a moment. In a use case where you have to include taxes or interest, how would you model that in the transaction.
[ {:account cash :deposit 100} {:account taxes :withdraw 20} {:account sales : withdraw 80} ] as a example
Now you mentioned for it to be valid
, the :deposit 100
should be equal to the withdraw
, right?
You should have {:account cash :deposit value}
separate from your vector containing your :withdraw
maps
That way, you can run map
on your vector to sum up your :withdraw
values and compare that directly to the value of (get {:account cash :deposit value} :deposit)
If the values are equal, then good, it's valid. Otherwise, do something else to inform the user that it's invalid
a vector [ {:account bank : withdraw 100} ] and a vector [{:account cash :deposit 100}]
there might be a case where you withdraw from just the bank but deposit into 2 different accounts
chips when I try this ` (reduce (fn[acc] (+ acc (get {:account bank :deposit value} :withdraw))) transactions ))'
usually, your function's arguments are the collection you're passing and each item in the collection
(map #(get % :deposit) transactions)
is the same as (map (fn [transaction] (get transaction :deposit)) transactions)
I think I have a idea , The into takes care that all the amounts are in a map so reduce could handle it
the vector of all the values is then run into a simple (reduce + ...)
which should give you the sum of all :deposit
values
into
is a very handy function if you want to change what type of collection something is
I initially started developing everything in Clojure before moving to CLJ+CLJS/Reagent
Time's not really on my side, since it's part of a work assignment I received since November
how to make this function smaller `(if (not(zero? ( - (reduce + (into [] (map #(get % :withdraw) withdraw-tranactioons))) (reduce + (into [] (map #(get % :deposit) deposit-tranactions))))))'
if (not(zero? ( - (reduce #(+ (:withdraw %2) %1) 0 w) (reduce #(+ (:deposit %2) %1) 0 d))))
Hi everyone!… how important is to know the Java library ecosystem in order to create real applications in Clojure? I come from a C++ background so I am very unfamiliar with the Java libraries.
it is hard to avoid learning at least something about the core Java API libraries (I/O, collections, strings, dates)
Clojure generally takes the approach that it will embrace the host (JVM) library when it has nothing to add - so that stuff is often invoked directly via Java interop
similarly, there are many useful Java libraries and it is often easiest to interact with them directly
Ok, that sounds reasonable. I guess I should focus on learning Clojure and “jump” to Java land as needed. What do you mean with collections?, Stacks? Queues?