Fork me on GitHub
#clojure
<
2016-01-15
>
arrdem01:01:59

I note that doall is just a pun for dorun. Should one of them be preferred?

arrdem01:01:28

Wow I can't read the docs. dorun always returns nil, where doall always returns the forced coll. My bad.

ghadi03:01:13

arrdem: there is a good site called grimoire where you can look docs up

fappy04:01:16

Hello simple_smile I'm wondering why a particular automat build in Travis CI passed despite ClassNotFoundExceptions ... the related snippet is in #C0AB48493

hans07:01:24

what mustache library do you recommend?

hans07:01:43

(= "you" everyone)

jaen08:01:18

I don't use mustache personally, but I've heard stencil is pretty nice.

seancorfield08:01:49

Leiningen uses Stencil for templates.

danielwoelfel08:01:04

Anybody have a clever way to turn a vector of maps with the same structure into a single map keyed by one of the keys in the map. For example, {{:a 1, :b 2}, {:a 3 :b 4}] => {1 {:a 1 :b 2}, 3 {:a 3 : b 4}}

danielwoelfel08:01:28

Best I can come up with is (zipmap (map :a v) v)

danielwoelfel08:01:49

But it's not as efficient as a reduce

dm308:01:50

(group-by :a) ?

danielwoelfel08:01:45

Close, but I don't want it to give me a vector of results for each key

danielwoelfel08:01:58

Good idea about group-by, though. I looked at the source and it uses a reduce with transients. I might get some extra points for using transients simple_smile

hans08:01:19

@jean @seancorfield @delaguardo Thanks! I'll go with stencil for now.

jethroksy09:01:07

I've defined a macro that generates a function

jethroksy09:01:19

(defmacro def-errors [k v]
  `(defn ~(-> k name symbol) []
     (error-page ~v)))

jethroksy09:01:35

macroexpand tells me it works

jethroksy09:01:27

(macroexpand (def-errors :404 "404"))
=> #'edubot.pages.errors/404

jethroksy09:01:50

my intention is to loop over a map and generate functions based on that

jethroksy09:01:48

(def error-map {:error-403 "Error 403. Permission Denied."
                :error-404 "Error 404. Page Not Found."})

(for [[k v] error-map]
  (def-errors k v))

jethroksy09:01:19

but the output of the last expression is just multiple definitions of function k:

=> (#'edubot.pages.errors/k #'edubot.pages.errors/k)

jethroksy09:01:28

I've already confirmed that k and v in the for loop are mapped correctly to the keywords and strings separately

jethroksy09:01:35

what is causing this behaviour?

dm309:01:13

the macro receives k as the argument

dm309:01:16

not the value of k

dm309:01:50

to do stuff like that dynamically you'll need eval or intern the vars directly

jethroksy09:01:56

hmm let me retry

mbertheau10:01:24

I was trying to #_-comment a thing with metadata and found out that it's enough to comment out the meta data like this: #_^{:key :a} [:a]. However, before that I tried to comment out both the meta data and the value itself, and got a result I don't understand: [#_^{:key :a} #_[:a] ^{:key :b} [:b]] is not [:b] but []. Why?

jaen10:01:21

Well, exact answer would require someone who knows the Clojure reader Java code, but it looks as if Clojure reader pushes the reader macros on a stack and then applies it to forms by pushing from that stack. So this reader macro will then apply to the next form that's read, and since #_ comments out both metadata and the form it will be ^{:key :b} [:b].

jaen10:01:58

I guess this would also explain this code - https://github.com/ztellman/automat/blob/master/src/automat/core.cljx#L157 - people were wondering about here not long ago.

ronb13:01:31

@danielwoelfel: (into {} (map (juxt :a identity)) [{:a 1 😛 2} {:a 2 😛 3}])

ronb13:01:51

not sure how fast it is though

ronb13:01:57

oops without the smileys simple_smile

jarodzz13:01:02

i am using core.async. my question is if i thread(while true ( go some function))). would it end up running out of server resource?

jarodzz13:01:31

i am new to core.async. and there is API usage, but not much info about design patterns

jarodzz13:01:47

i am working on a web service, about 1 million msg per day

jarodzz13:01:04

it's like get a request, use some other web service to enrich it, and save it to db

jarodzz13:01:16

so i am designing it like 3 channels, and thread read from channel, and go call a web service, after get response, save to the next channel.

jarodzz13:01:17

the point is , the second service is slow, so some times the first channel exceed its limit.

jarodzz13:01:35

i am not sure i am using it right

yogthos13:01:07

@seancorfield: lein now supports using a custom renderer too, you can pass it in to renderer when you initialize it

jonahbenton14:01:05

hey @jarodzz, those are common issues- multiple collaborating services in a pipeline taking differing amounts of time. in those cases it's up to you to decide, based on the requirements of the overall problem you're solving, what policies, or business rules, you want to have to handle the different circumstances. once you have clarity on your rules, then you can settle on an architecture/implementation, which maybe uses core.async or maybe does not. for example, if the goal of the web service is just to save/ack this incoming data, and the response doesn't depend on the enrichment step, then you might just want to write the incoming requests directly to the db, and set up a background task to ensure that each of them is appropriately enriched. in contrast, if the web service responses depend on the enrichment step, then you basically have a synchronous problem and you need to provision for 1M calls/day to the enrichment service- or find a faster enrichment service (or maybe employ a cache, etc) lots of variations in between those, but try to define the policies you want to have first, and then see if core.async is an appropriate mechanism

jarodzz14:01:08

@jonahbenton: thanks for the details. in this case, i do need a realtime response.

jarodzz15:01:04

the prototype works with a queue, as a temp buffer. but my problem is, if i read 1k from queue, go call step1, async put results to channel 1. then read from channel1 to go call step2. but if step2 is slow, i need to wait for it is empty to get new requests. i have no way to tell whether a channel is empty

jonahbenton15:01:06

gotcha. so it sounds like the use of core.async has introduced a dependency between the slowness of the enrichment and your ability to service new requests? because you are waiting to deliver a response to request 1 before serving request 2?

jarodzz15:01:38

y. something like that. more like if i have 3 channel, moving requests 1->2->3, each step will enrich something. but i can't get new requests before channel1 is empty. otherwise, it's gonna fail at >!! ch

jarodzz15:01:58

but i can't tell when channel1 is empty.

jarodzz15:01:35

maybe i am using it wrong. simple_smile. i'm reading some core.async articles from reddit.

lucasbradstreet15:01:14

An #onyx / #datomic experience report written by @robert-stuttaford, that some of you may be interested in "just a small experience report which i hope will help some other Onyx users out: https://twitter.com/robstuttaford/status/687954517325950976"

robert-stuttaford15:01:50

oh, heh, yeah simple_smile any questions most welcome!

jonahbenton15:01:58

@jarodzz yeah, it's a neat pattern, but it sounds like it doesn't capture the semantics you need. what you need is a synchronous pipeline that takes a ticker, downloads the ticker data, transforms, and then inserts, e.g. (-> ticker download transform insert). your web service handler could spin up a go block for each incoming ticker, and wait on a channel for the insert to complete to return a result to the user.

jarodzz15:01:37

got it. i'll give it a try. thanks,

seancorfield17:01:35

Good to know! I’ll have to take a closer look as I’m building a template system for Boot right now, based on Leiningen. https://clojurians.slack.com/archives/clojure/p1452865567013441

mpenet17:01:39

@jarodzz: there was an interesting post in the google group about a similar problem recently: https://groups.google.com/d/msg/clojure/_8fHJ3J-MYg/LCK9JbykCwAJ

robert-stuttaford17:01:10

@mpenet: you’re welcome 😛

jcomplex21:01:44

has anyone tried interacting with a C# service through REST?

akiva22:01:46

It shouldn’t matter if the service is sending back JSON.

akiva22:01:40

Look into Cheshire for JSON processing (https://github.com/dakrone/cheshire).

derwolfe22:01:44

hi - I’m working with multimethods and am trying to write a dispatch method based on class for Byte-Arrays. I’m not having much luck. Anyone have a tip for what I might use to dispatch on this?

derwolfe22:01:32

I think I’ve found it (defmethod encrypt (Class/forName "[B") [key message]. simple_smile