Fork me on GitHub
#beginners
<
2018-08-25
>
neural00:08:07

anybody knows how to override a dependency with local ~/.m2 ??

seancorfield00:08:34

@ryan.russell011 What are "regular Clojure queries"? You mean embedding SQL strings directly into your Clojure source code?

seancorfield00:08:03

A lot of people don't like doing that -- editors don't give SQL syntax highlighting when it's embedded in a string, so HugSQL's approach works better for them. I personally value seeing the actual query inline with the code rather than needing to look at multiple files (so that's my "con" for HugSQL).

moo00:08:40

how does one map exponentiation to the power of two?

quadron00:08:11

@jm.moreau what do you mean?

moo00:08:21

I want to square all the numbers in (partition 2 1 (range 1 32))

moo00:08:21

((1 2) (2 3) ... should become ((1 4) (4 9) ... )

quadron00:08:55

(map (partial map #(Math/pow % 2)) (partition 2 1 (range 1 32)))

moo00:08:56

I’m using project Euler to try to understand FP. I’m trying to solve a+b+c= 1000, where a < b < c and a^2+b^2=c^2

moo00:08:59

hmm, I tried apply from your last set of advice

moo00:08:31

(map (partial map #(some fn) stuff still doesn’t make intuitive sense

moo00:08:50

at least to me at the moment

neural00:08:14

@jm.moreau Do you understand map?

moo00:08:30

well, obviously I could understand it better 😉

moo00:08:55

I thought map applies fn to each element in a seq

moo00:08:25

(individually)

moo00:08:30

returning another seq

moo00:08:48

(fn(a), fn(b), …)

moo00:08:38

I thought of it like a mapping in math, where everything is mapped (so a nice mapping—surely there is as word for that)

neural00:08:16

no! its not that!

neural00:08:12

Its just as you said: >I thought map applies fn to each element in a seq

neural00:08:43

so (defn square [x] (Math/pow x)) is our fn.

neural00:08:02

just (map square '(1 2 3 4 5 6))

moo00:08:50

trying it.

neural00:08:00

(defn square [x] (Math/pos x 2))

moo00:08:32

caught that 🙂

neural00:08:50

but you want on '((1 2) (3 4)) so

moo00:08:38

can I destructure at the same time?

quadron00:08:53

(map (fn[x](Math/pow x 2)) [1 2 3]) = [1 4 9] (map (fn[x](Math/pow x 2)) [[1,2] [3,4]] will try to take a list to the second power and it will fail so we have to get one level deeper and map the map: partial makes its first argument close over the rest of the arguments, so that we could lift it by the outer map (map (partial map (fn[x] (Math/pow x 2))) [[1,2] [3,4]])

neural00:08:38

(map (fn [lst] (map square lst)) '((1 2) (3 4)))

moo00:08:38

@veix.q5 yeah that makes sense

moo00:08:11

so assuming my list is a bunch of a’s and b’s such that a <b

moo00:08:13

what I want to do is

moo00:08:40

calc sqrt(a^2 + b^2) +a +b

moo00:08:44

over that list of lists

moo00:08:53

that’s going to be…

moo00:08:05

or rather would I destructure it like this? (map (partial map (fn [[a b]] (math on a and b here) (my partition here)

moo00:08:57

trying to get a sense of it (map (partial map (fn [[a b]] (+ a b))) (partition 2 1 (range 1 32))) doesn’t work

moo00:08:02

(just a simple attempt to add them

quadron00:08:06

you won't need double maps here

quadron00:08:41

because the destructuring is already unwrapping a level of nesting

moo00:08:48

I’d like to map sqrt(a^2 + b^2) +a +b over it

moo00:08:04

so it becomes (fn a b)

quadron00:08:43

(map (fn[[a,b]] (+ ( a a) ( b b) a b) collection)

quadron00:08:28

you should keep in mind what the type of the collection is.

moo00:08:30

trying stuff… @veix.q5 that helped I didn’t realized a “lifted” out of one list

moo00:08:15

great everything works. thanks @veix.q5 and @neural.works.com!

moo00:08:30

My code runs, and now I see I made some math mistakes. 🙂

moo00:08:32

is there a way to combine all permutations of lists?

moo00:08:38

List a = (1, …, n), list b similarly has n elements and so does list c. Can I make new-list of [a1, b1, c1] for all permutations?

quadron00:08:31

(for [x [1 2 3] y [4 5 6] z [7 8 9]] [x y z])

moo00:08:31

wow, wtf is going on there?!

moo01:08:51

it seems that for is not lazy

Alex Miller (Clojure team)14:08:19

for is lazy (but if you are at the repl, the repl will print the result and force eval)

hiredman01:08:35

(for [x [1 2 3] y [4 5 6] z [7 8 9]] [x y z])

(mapcat (fn [x]
          (mapcat (fn [y]
                 (map (fn [z]
                        [x y z])
                      [7 8 9]))
               [4 5 6]))
     [1 2 3])

moo01:08:38

great I’ll look up mapcat. Thanks for the clues guys

quadron15:08:24

what is the name of the mathematical category that unlike set admits repetition?

quadron15:08:56

I am not looking for the list, because I don't care about order

quadron15:08:40

never mind! its multiset

dpsutton16:08:51

Bag is a common name as well

✔️ 4
g17:08:00

hey guys, any suggestions for resources for using clojure within cljs projects?

g17:08:17

specifically i’m working on including macros in a fully-cljs project