Fork me on GitHub
#beginners
<
2016-09-10
>
credulous01:09:25

@seancorfield @codonnell Thanks, that helps a lot!

eslachance04:09:07

oooooooh I just found event emitters. This is what I needed \o/

eslachance04:09:39

but http://github.com/clojurewerkz/eep hasn't been updated in 2 years 😞

shaun-mahood06:09:11

@eslachance: I've never used anything like that, what do you want to use them for? Looks interesting!

madstap09:09:06

@straistra You need to slurp at macroexpansion time https://gist.github.com/noprompt/9086232

credulous09:09:23

@seancorfield Thanks for the help… just to close the loop, here’s the function. I modified it a bit to keep the embedded maps intact rather than rolling their stats into to top-level map.

credulous09:09:40

(defn summarize  [data acc]
   (reduce-kv  (fn  [acc k v]
                 (cond
                   (number? v)  (update acc k  (fnil + 0) v)
                   (map? v)  (assoc acc k  (merge-with summarize (k data) (k acc) ))
                   :else acc))
              acc data))

credulous09:09:32

Now with my seq of records “s” I can just (reduce summarize {} s). Works a treat, thanks a lot!

straistra09:09:50

@madstap Hey thanks! I'll check that out when I get home.

eslachance14:09:13

@shaun-mahood I'm just so comfortable with events in node.js, that I want to use something similar in Clojure. I might end up using core.async or clojurewerks/Meltdown I dunno yet.

shaun-mahood14:09:04

@eslachance: Have you thought about trying Clojurescript with NodeJS? My first real project was in CLJS and it was pretty nice being able to use the JS interop.

eslachance14:09:17

Well. let me explain the idea first.

eslachance14:09:30

My "bright" idea is to ambitiously create a library for bots in Discord

eslachance14:09:52

Which sits between the Discord API, that uses both websockets and get/post/put events

eslachance14:09:59

And the end-user creating a bot that will wait for specific events from the library (which I call Dithcord, because I'm funny like that). So, say the API sends a websocket event with a new message, the person making the bot would add an event listener that waits for a "message" event, and do stuff.

eslachance14:09:54

So like

(mr/on reactor ($ "message") (fn [message, server] (do something with message)))

eslachance14:09:39

or

(mr/on reactor ($ "newUserOnServer") (fn [event] (welcome the new user)))

eslachance14:09:59

(that's with Meltdown, just pulling examples from the readme)

eslachance14:09:17

From what I've seen most people just roll their own "library" by interacting directly with the REST API and websockets, but I want to make this a semi-friendly helper library that is as feature-complete as the other ones (there's probably 2 dozen libs out there, 4 are in node.js)

eslachance14:09:30

Does that make sense @shaun-mahood ?

eslachance14:09:36

I have to figure out websockets first and how to communicate/ handle events, but I have stylefruits/gniazdo for that I just need to... well... kinda learn clojure 😛

shaun-mahood15:09:36

@eslachance: Sounds like fun!

eslachance15:09:37

For the project I want to do ultimately I'll probably be using clojurescript with re-frame and stuff but I really, really like the idea of making my own library and then making tutorials and videos for it. That's my "thing" 😄

shaun-mahood15:09:26

Very cool, aways need more of that.

rahulpilani18:09:13

I needed some help setting up cider

rahulpilani18:09:12

for some reason I am not getting any completion suggestion

eslachance21:09:45

Yessss I have a websocket "client" in clojure talking to a websocket server and they're pinging each other. \o/ success

eslachance22:09:04

Alright. first real noob question. I have a ping-pong function that needs to be called from within my websocket... but it needs to call the websocket send-msg. This is my first real challenge figuring out how to work with clojure's "top to bottom" definitions (aka "you can't define a function before creating it). How do I call ping-pong from my socket (:on-connect) and call ws/send-message from ping-pong?

eslachance22:09:10

(defn ping-pong [delay]
  (go-loop []
    (printf "Sending a ping request")
    (ws/send-message "ping")
    (recur)))

(def socket
  (ws/connect
    ""
    :on-connect
      (fn) [] (ping-pong 5000)
    :on-receive
      (fn [message] (receive-message message))
    :on-error
      (fn [error] (handle-error error))))

eslachance22:09:51

wait do I just need to pass the socket?

mfikes22:09:43

@eslachance I’m not following specifically what you are doing above, but I’d add that you can use declare to side-step what I believe you describe as the “top to bottom” issue.

eslachance22:09:51

Ah ok so declare is like a placeholder?

mfikes22:09:26

@eslachance Yes, that’s roughly how I think of it mentally. It’s like saying: This var will be defined later on.

eslachance22:09:41

Thanks! 😄

dpsutton22:09:00

also notice you aren't using the delay

dpsutton22:09:13

and there seems be no need for the go-loop there

eslachance22:09:34

Yeah I'm still figuring things out. I think the "order" thing is probably why the code I'm basing myself on is using async channels and not what I'm trying to do.

eslachance22:09:12

my original socket ping/pong is still going strong though 😄