Fork me on GitHub
#beginners
<
2016-09-29
>
adrien07:09:30

@dorianc.b no, you are not forced to use clojurescript it's client side, you can use whatever you prefer what I did: - clojure for the server, to learn the language - javascript on the client to check that my server works as I want it to - now clojurescript on the client

adrien08:09:43

when you see how powerful clojurescript and its ecosystem are, I guess you'll move to clojurescript as well 🙂

dimovich12:09:00

what regex can capture the word surrounded by another word (from either sides)... like: #"house (\w+) | (\w+) house"

dimovich12:09:29

maybe there is a more elegant way of writing it

fatihict12:09:30

@dimovich Maybe something like this:

(\w+)?house(\w+)?

singen12:09:52

I’m trying to write an algorithm for modified competition ranking (https://en.wikipedia.org/wiki/Ranking#Modified_competition_ranking_.28.221334.22_ranking.29) in clojure, but I’m not making any headway into something that would be elegant. How could I prevent lookups into previous map values?

singen12:09:38

Anyone ever done anything similar to this?

singen12:09:58

Standard ranking is trivial (map-indexed (fn [idx itm] (conj itm {:rank (+ idx 1)})) leaderboard))

singen12:09:22

I would have done this in five minutes in Java

dominicm14:09:47

@singen So you have this code?

dominicm14:09:54

I think you might want a reducer here really. Because you need to "look back" as you build up, to check for equivalents.

singen14:09:27

I’ve been scratching my head over how to map with previous value

dominicm14:09:27

Check out reduce I think 🙂

singen14:09:34

But I can’t find any examples that are enough alike

dominicm14:09:43

Alternatively, start with the map-indexed and massage it after

singen14:09:21

It won’t work, because you need the result of the previous iteration

singen14:09:36

Reduce looks like it might do what I want, but all the examples I find are extremely dissimilar to what I want to do. I can’t figure out the syntax, really.

dominicm14:09:56

It's a little hard to explain, essentially you have an "accumulator" and a "new item"

dominicm14:09:47

And each time the fn is called (with accumulator, and the next item from the list), you return a new value for the accumulator

singen14:09:34

Could you, for example make map-indexed with reduce?

dominicm14:09:48

Probably, yeah

dominicm14:09:59

I think you can build most things with reduce actually

dominicm14:09:21

Just putting together a related example for you 🙂

singen14:09:26

Oh, thanks!

dominicm14:09:47

(reduce
  (fn [ld itm]
    (let [last-item (last ld)
          last-value (first last-item)
          last-rank (:rank (last last-item))]
      (if (= itm last-value)
        (conj ld [itm {:rank last-rank}])
        (conj ld [itm {:rank (inc (count ld))}]))))
  []
  [1 2 2 4])

dominicm14:09:51

That does standard competition ranking. Doing modified ranking is a little more complex, plus I'll steal all the fun if I solve it for you 😉.

singen14:09:20

That looks like it will help, a lot

dominicm14:09:37

Modified ranking is slightly harder to implement, but not too difficult. There is probably a better way to do this, but reduce is what comes to mind. I'm sure someone will weight in with a one-liner at some point.

dominicm14:09:39

No problem!

dominicm14:09:47

Ask again if you need further help

dorianc.b14:09:57

I’m pretty much in the beginning of my clojure learning and I’m learning about maps but I got this error. Is conj not applicable to maps?(conj {:b 2,:a 1} :c 3) IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:542)

singen14:09:40

(conj {:b 2,:a 1} {:c 3})

singen14:09:44

Does that answer your question? 🙂

dorianc.b14:09:03

Yea just figured it out after I asked lol. Not much syntax but it’s a taking a bit to sink in

singen14:09:44

@dominicm I just figured out how reduce works and solved my problem 🙂

curlyfry17:09:17

@dorianc.b The most common way to do it is to use assoc, though: (assoc {:b 2 :a 1} :c 3)

dorianc.b17:09:32

thanks ill keep that in mind. I’m currently just going through the Clojure the brave book so I just started

josh_tackett22:09:20

App won’t build on heroku, need help quick:

-----> SSH app detected
-----> Installing ngrok...  !     Push rejected, failed to compile SSH app.
 !     Push failed